Advertisement
jeff69

Untitled

Oct 8th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. typedef long double ld;
  5. string h;
  6. int n,R;
  7.  
  8. int poi[100009];
  9. set<pair<int,int>> sr;
  10. int main()
  11. {
  12. int t;
  13. cin>>t;
  14. while(t--){
  15. sr.clear();
  16. int n,q;
  17. cin>>n>>q;
  18. int lw,ans;
  19. lw=ans=0;
  20. lw=1;
  21. memset(poi,0,sizeof poi);
  22.  
  23. for(int i=0;i<n;i++)sr.insert({0,-1*(i+1)});
  24. for(int i=0;i<q;i++)
  25. {
  26. int x,y;
  27. scanf("%d%d",&x,&y);
  28. sr.erase({poi[x],-x});
  29. poi[x]+=y;
  30. sr.insert({poi[x],-x});
  31. auto it=sr.end();
  32. it--;
  33. if(lw!=-1*(it->second))
  34. {
  35. lw=-1*(it->second);
  36. ans=i+1;
  37.  
  38. }
  39. }
  40. cout<<ans<<endl;
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement