fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct node
  4. {
  5. int w,id;
  6. bool operator < (const node &other) const {
  7. return w > other.w;
  8. }
  9. };
  10. long long res=0,n;
  11. vector<int> pos[1000005];
  12. int main()
  13. {
  14. freopen("FINE.inp","r",stdin);
  15. freopen("FINE.out","w",stdout);
  16. cin >> n;
  17. for(int i = 1; i <= n; i++)
  18. {
  19. long long x,y;cin>>x>>y;
  20. pos[x].push_back(y);
  21. }
  22. priority_queue<int,vector<int>,greater<int>> q;
  23. for(int tgian=1;tgian<=1e6;tgian++){
  24. for(int i : pos[tgian]){
  25. q.push(i);
  26. }
  27. if(!q.empty()){
  28. int i=q.top(); q.pop();
  29. i--;
  30. if(i!=0) q.push(i);
  31. else res++;
  32. }
  33. res+=q.size();
  34. }
  35. cout<<res;
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0.01s 26984KB
stdin
Standard input is empty
stdout
Standard output is empty