Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 101102c.cpp
- *
- * Oct 24, 2016
- */
- #include <iostream>
- #include <cstdio>
- #include <set>
- using namespace std;
- typedef pair<int, int> ii;
- const int N = int(1e5) + 5;
- int a[N], n, q;
- set<ii> s;
- int main() {
- // freopen("input.inp", "r", stdin);
- int tst; scanf("%d", &tst);
- while (tst--) {
- scanf("%d%d", &n, &q);
- s.clear();
- for (int i = 1; i <= n; i++) {
- a[i] = 0;
- s.insert(make_pair(0, i));
- }
- int res(0), winner(1);
- for (int i = 1; i <= q; i++) {
- int idx, sc; scanf("%d%d", &idx, &sc);
- s.erase(make_pair(a[idx], idx));
- a[idx] -= sc;
- s.insert(make_pair(a[idx], idx));
- __typeof(s.begin()) it = s.begin();
- if (it->second != winner) {
- winner = it->second;
- res = i;
- }
- }
- printf("%d\n", res);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement