#include<map>//主键为power 副键为id map自动根据主键进行排序
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
map<int,int> club;//角斗场club 设置主键副键为int
map<int,int>::iterator j;
club[1000000000]=1;//老板强的一批
int n,id,power;
cin>>n;
while(n--)
{
cin>>id>>power;
j=club.lower_bound(power);
//map::lower_bound(key)返回map中第一个大于等于key的主键的迭代器
//map::lower_upper(key)返回map中第一个大于key的主键的迭代器、这两个函数在<map>里
if(j==club.begin())
{//如果返回第一个迭代器,说明新来的最弱,那么找第二弱的打
cout<<id<<" "<<j->second<<endl;
}
else if(j==club.end())
{//如果返回最后一个迭代器,说明新来的最强,那么找第二强的打
j--;//从老板位置走到第二强者位置
cout<<id<<" "<<j->second<<endl;
}
else
{//实力不上不下,那么要比较与左右的绝对值
int right=(j->first)-power;
j--;
int left=power-(j->first);
if(right>=left)//绝对值差值>=0就打弱的
{//就打你了,弱者
cout<<id<<" "<<j->second<<endl;
}
else
{//bad luck!
j++;
cout<<id<<" "<<j->second<<endl;
}
}
//打完了,你可以成为我们的一员了!(信息存入)
club[power]=id;
}
return 0;
}