Advertisement
Guest User

101102c.cpp

a guest
Oct 24th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. /*
  2.  *  101102c.cpp
  3.  *
  4.  *  Oct 24, 2016
  5.  */
  6.  
  7. #include <iostream>
  8. #include <cstdio>
  9.  
  10. #include <set>
  11. using namespace std;
  12.  
  13. typedef pair<int, int> ii;
  14.  
  15. const int N = int(1e5) + 5;
  16.  
  17. int a[N], n, q;
  18. set<ii> s;
  19.  
  20. int main() {
  21. //    freopen("input.inp", "r", stdin);
  22.  
  23.     int tst; scanf("%d", &tst);
  24.     while (tst--) {
  25.         scanf("%d%d", &n, &q);
  26.         s.clear();
  27.         for (int i = 1; i <= n; i++) {
  28.             a[i] = 0;
  29.             s.insert(make_pair(0, i));
  30.         }
  31.  
  32.         int res(0), winner(1);
  33.         for (int i = 1; i <= q; i++) {
  34.             int idx, sc; scanf("%d%d", &idx, &sc);
  35.  
  36.             s.erase(make_pair(a[idx], idx));
  37.             a[idx] -= sc;
  38.             s.insert(make_pair(a[idx], idx));
  39.  
  40.             __typeof(s.begin()) it = s.begin();
  41.             if (it->second != winner) {
  42.                 winner = it->second;
  43.                 res = i;
  44.             }
  45.         }
  46.  
  47.         printf("%d\n", res);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement