滑动窗口搞一搞
#include<bits/stdc++.h>
#include<bitset>
#include<unordered_map>
#define pb push_back
#define bp __builtin_popcount
#define TIME cout << "RuningTime: " << clock() << "ms\n", 0
#define ls x<<1
#define rs x<<1|1
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int MOD=9901;
const int mod = 1e9+7;
const double PI=3.14;
int lowbit(int x){return x&-x;}
ll gcd(ll x, ll y){ return y == 0 ? x : gcd(y, x%y); }
ll lcm(ll x, ll y){ return x / gcd(x, y)*y; }
inline ll dpow(ll a, ll b){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t) % MOD; b >>= 1; t = (t*t) % MOD; }return r; }
inline ll fpow(ll a, ll b,ll p){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t) % p; b >>= 1; t = (t*t) % p; }return r; }
priority_queue<int, vector<int>, greater<int> > q;
int main()
{
int n;
cin >> n;
vector<vector<int>> nums;
vector<int> a;
while(n--)
{
do
{
int x;
cin >> x;
if(!cin)
{
break;
}
a.push_back(x);
} while (cin.get() != '\n' );
nums.push_back(a);
a.clear();
}
/* for(int i = 0;i < arr.size();i ++ )
for(int j = 0;j < arr[i].size();j++)
cout << arr[i][j] << " ";*/
multimap<int,int> mmp1 ;
for(int i = 0;i < nums.size();i ++ )
{
for(int j = 0;j < nums[i].size();j++)
{
mmp1.insert(pair<int,int>(nums[i][j],i));
}
}
multimap<int,int>::iterator left = mmp1.begin();
multimap<int,int>::iterator right =mmp1.begin();
int res = INT_MAX;
int leftv = 0;
int rightv= 0;
int k = nums.size();
unordered_map<int,int> curmap;
while( right != mmp1.end() )
{
curmap[right->second] ++;
while(curmap.size() == k )
{
if( right->first - left->first < res)
{
res = right->first - left->first;
leftv = left->first;
rightv = right->first;
}
curmap[left->second] --;
if( curmap[left->second] == 0)
{
curmap.erase(left->second);
}
left++;
}
right++;
}
cout << leftv << " " << rightv << endl;
//system("pause");
return 0;
}
/*
3
4 10 15 24 26
0 9 12 20
5 18 22 30
20 24
*/