# Include <cstdio> # include <iostream> # include <cstring> # include <cmath> # include <map> # include <algorithm> # include <cstdlib> using namespace std; int main () {int n; int id, g; while (scanf ("% d", & n) {map <int, int> m; m [1000000000] = 1; for (int I = 1; I <= n; ++ I) {scanf ("% d", & id, & g ); printf ("% d", id); map <int, int>: iterator it; it = m. lower_bound (g); // finds the first location greater than or equal to g in binary mode. if not, returns the end location if (it = m. End () {it --; printf ("% d \ n", it-> second);} else {if (it = m. begin () {printf ("% d \ n", it-> second);} else {int pos = it-> first; int tmp = it-> second; it --; printf ("% d \ n", (pos-g) <(g-it-> first )? Tmp: it-> second) ;}} m [g] = id ;}} return 0 ;} # include <cstdio> # include <iostream> # include <cstring> # include <cmath> # include <map> # include <algorithm> # include <cstdlib> using namespace std; int main () {int n; int id, g; while (scanf ("% d", & n) {map <int, int> m; m [1000000000] = 1; for (int I = 1; I <= n; ++ I) {scanf ("% d", & id, & g ); printf ("% d", id); map <int, int>: iterator it; it = m. lower_bound (g); // Find the first position greater than or equal to g in the second part. if not, return the end position if (it = m. end () {it --; printf ("% d \ n", it-> second);} else {if (it = m. begin () {printf ("% d \ n", it-> second);} else {int pos = it-> first; int tmp = it-> second; it --; printf ("% d \ n", (pos-g) <(g-it-> first )? Tmp: it-> second) ;}} m [g] = id ;}} return 0 ;}