y总基于排序的做法
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int n;
int a[N];
int main()
{
int cnt;
cin >> cnt;
string line;
getline(cin, line); //忽略第一行的空格
while (cnt --)
{
getline(cin, line);
stringstream ssin(line);
while (ssin >> a[n]) n ++;
}
sort(a, a + n);
int res1, res2;
for (int i = 1; i < n; i ++)
{
if (a[i] == a[i - 1]) res2 = a[i]; //重号
else if (a[i] >= a[i - 1] + 2) res1 = a[i] - 1; //断号
}
cout << res1 << " " << res2 << endl;
return 0;
}