fork download
  1. #include<bits/stdc++.h>
  2. #define F first
  3. #define S second
  4. using namespace std;
  5. pair<int,int>q[1000001];
  6. priority_queue<int>pq;
  7.  
  8. int main(){
  9. ios_base::sync_with_stdio(0);
  10. cin.tie(0);
  11. int n,m=0,a,b,s=0;
  12. cin>>n;
  13. for(int i=0;i<n;i++){
  14. cin>>a>>b;
  15. q[i].F=a*-1;
  16. q[i].S=b;
  17. m=max(m,a);
  18. }
  19. sort(q,q+m);
  20. int zm=q[n-1].F-1;
  21. cout<<q[n-1].F;
  22. for(int i=n-1;i>=0;i--){
  23. if(q[i].F==zm){
  24. pq.push(q[i].S);
  25. }
  26. else{
  27. zm=q[i].F;
  28. pq.push(q[i].S);
  29. s+=pq.top();
  30. pq.pop();
  31. }
  32. }
  33. cout<<s;
  34. }
Success #stdin #stdout 0s 5304KB
stdin
5
3 2
1 3
2 1
2 4
1 1
stdout
-111