map, 用实力值当做关键字
#include <iostream>
#include <memory.h>
#include <map>
#include <stdio.h>
#define IN (1<<28)
using namespace std;
int N;
map <int,int> record;
int main()
{
cin >> N;
record[1000000000] = 1;
for( int i = 1; i <= N; i++ )
{
int id,value;
scanf("%d %d", &id, &value);
record[value] = id;
map<int,int>::iterator p = record.find(value);
map<int,int>::iterator j;
map<int,int>::iterator k;
if( p != record.end() )
{
if( p == record.begin() )
{
j = p;
j++;
cout << p->second << ' ' << j->second << endl;
}
else
{
j = p;
j++;
k = p;
k--;
int up = j->first - p->first;
int low = p->first - k->first;
if( low <= up )
{
cout << p->second << ' ' << k->second << endl;
}
else
{
cout << p->second << ' ' << j->second << endl;
}
}
}
else
break;
}
return 0;
}