Răspuns :
#include <iostream>using namespace std;
int main(){ int n, a, b, amin, bmin, dmin, imin; cin >> n >> amin >> bmin; imin = 1; if(amin-bmin > 0) dmin = amin-bmin; else dmin = bmin-amin; for(int i=2;i<=n;++i){ cin >> a >> b; int d = a>b?a-b:b-a; if(d <= dmin) dmin = d, amin = a, bmin = b, imin = i; } cout << imin; return 0;}
int main(){ int n, a, b, amin, bmin, dmin, imin; cin >> n >> amin >> bmin; imin = 1; if(amin-bmin > 0) dmin = amin-bmin; else dmin = bmin-amin; for(int i=2;i<=n;++i){ cin >> a >> b; int d = a>b?a-b:b-a; if(d <= dmin) dmin = d, amin = a, bmin = b, imin = i; } cout << imin; return 0;}