Advertisement
Guest User

TASK B

a guest
Sep 21st, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <cstring>
  6. #include <string>
  7. #include <queue>
  8. #include <set>
  9. #include <map>
  10. #include <vector>
  11. #include <algorithm>
  12. #include <cmath>
  13.  
  14. using namespace std;
  15.  
  16. typedef unsigned long long ull;
  17.  
  18. const int MAXN=111111;
  19.  
  20. int n,i,j,x,t;
  21.  
  22. pair<int,int> a[MAXN];
  23.  
  24. set<int> f;
  25.  
  26. int main()
  27. {
  28.     freopen("jumps.in","r",stdin);
  29.     freopen("jumps.out","w",stdout);
  30.  
  31.     cin >> n;
  32.  
  33.     for (i=0;i<n;i++) {
  34.         cin >> x >> t;
  35.         a[i]=make_pair(x,t);
  36.     }
  37.  
  38.     sort(a,a+n);
  39.  
  40.     reverse(a,a+n);
  41.     for (i=1;i<=n;i++)
  42.         f.insert(i);
  43.     long long ans=0;
  44.     for (i=0;i<n;i++) {
  45.         int pos=a[i].second+1;
  46.         set<int>::iterator it = f.lower_bound(pos);
  47.         if (it==f.end()) {
  48.             ans+=(long long)a[i].first;
  49.         }
  50.         else {
  51.             f.erase(it);
  52.         }
  53.     }
  54.  
  55.     cout << ans << '\n';
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement