Ledger Nano X - The secure hardware wallet
SHARE
TWEET

summer

a guest Apr 6th, 2020 187 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<queue>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. struct info{
  7.     int a, b;
  8.  
  9.     bool operator< (const info &tmp) const {
  10.         return b < tmp.b;
  11.     }
  12. };
  13.  
  14. bool cmp_a(info i1, info i2){
  15.     return i1.a < i2.a;
  16. }
  17.  
  18. const int N = 1e5+10;
  19. info v[N];
  20. int n, m;
  21.  
  22. int main(){
  23.     cin >> n >> m;
  24.     for(int i=0; i < n; i++){
  25.         cin >> v[i].a >> v[i].b;
  26.     }
  27.     sort(v, v+n, cmp_a);
  28.     priority_queue<info> q;
  29.     int index = 0;
  30.     int ans = 0;
  31.     for(int i=0; i <= m; i++){
  32.         while(index < n and v[index].a <= i) q.push(v[index++]);
  33.         if(q.size()) ans += q.top().b, q.pop();
  34.     }
  35.     cout << ans << endl;
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top