http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp
#define _USE_MATH_DEFINES #include <iostream> #include <vector> #include <list> #include <cmath> #include <algorithm> using namespace std; int main () { int n,r; while (cin >> n >> r) { if (n == 0) { break; } list<int> w; for (int i=0; i < n; i++) { w.push_front(i+1); } for (int i=0; i < r; i++) { int p,c; cin >> p >> c; int tmp[c]; list<int>::iterator it = w.begin(); advance( it, (p - 1) ); for (int j=0; j < c; j++) { tmp[j] = *it; *it = 0; it++; } w.remove(0); for (int j=c-1; j >= 0; j--) { w.push_front(tmp[j]); } } list<int>::iterator it = w.begin(); cout << *it << endl; } return 0; }