Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll int
  4. #define endl "\n"
  5. #define ld long double
  6. #define pb push_back
  7. #define all(n) n.begin(),n.end()
  8. #define eb emplace_back
  9. #define pll pair<ll,ll>
  10. #define YES cout <<"YES"<<endl;
  11. #define NO cout <<"NO"<<endl;
  12. #define ff first
  13. #define ss second
  14. #define setpre(x) fixed<<setprecision(x)
  15. #define heap priority_queue
  16.  
  17.  
  18. const ll maxn=2e5+100;
  19.  
  20. const ll maxx=1e13;
  21. const ll mod=1000000007;
  22. const ll modGTG=1e6+9;
  23. const ll mod1=998244353;
  24. const ll base=27;
  25.  
  26. priority_queue<pll,vector<pll>,greater<pll>> q;
  27. vector<ll> adj[maxn];
  28. vector<ll> adj1[maxn];
  29. ll dd[maxn];
  30. ll cnt[maxn];
  31. map<ll,multiset<ll,greater<ll>>> mp;
  32.  
  33.  
  34. multiset<ll> st;
  35. int main()
  36. {
  37.      freopen("PENALTY.INP","r",stdin);
  38.      freopen("PENALTY.OUT","w",stdout);
  39.     ios_base::sync_with_stdio(0);
  40.     cin.tie(0);
  41.     cout.tie(0);
  42.     ll n,a,b;
  43.     cin>>n>>a>>b;
  44.     ll ans=0;
  45.     for (int i=1;i<=n;i++)
  46.     {
  47.         ll x,y;
  48.         cin>>x>>y;
  49.         mp[x].insert(y);
  50.         ans+=y;
  51.  
  52.     }
  53.     ll pre=a;
  54.     ll dunw=0;
  55.     for (auto p:mp)
  56.     {
  57.         ll nw=p.ff;
  58.         auto st1=p.ss;
  59.         if (nw<=a) continue;
  60.        if (nw<=b)
  61.        {
  62.            dunw=dunw+nw-pre;
  63.            pre=nw;
  64.        }
  65.        else
  66.        {
  67.            dunw=dunw+b-pre;
  68.            pre=b;
  69.        }
  70.         while (1)
  71.         {
  72.            // if (dunw<=0) break;
  73.             if (st1.size()==0) break;
  74.             auto it=st1.begin();
  75.             auto k=*it;
  76.             st.insert(k);
  77.             st1.erase(it);
  78.             dunw--;
  79.  
  80.         }
  81.         while (dunw<0)
  82.         {
  83.            dunw++;
  84.            st.erase(st.begin());
  85.  
  86.  
  87.         }
  88.     }
  89.     //cout <<ans<<endl;
  90.     while (!st.empty())
  91.     {
  92.         auto k=*st.begin();
  93.         ans-=k;
  94.         st.erase(st.begin());
  95.     //    cout <<k;
  96.     }
  97.     cout <<ans;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement