Cod sursa(job #2664987)

Utilizator OvidRata Ovidiu Ovid Data 29 octombrie 2020 20:49:57
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul II Marime 1.38 kb
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount


int t, n, l, x;
pii oi[100010];


ifstream fin("lupu.in"); ofstream fout("lupu.out");
#define cin fin
#define cout fout


int32_t main(){
INIT
cin>>n>>x>>l;
for(int i=1; i<=n; i++){
    cin>>oi[i].ft>>oi[i].sc;
}
sort(oi+1, oi+1+n);
int ind=0, ac=-(( (x-x%l) )+(((x%l)>0)?(l):(0)));
multiset<int> ms;
ll s=0;

while( (ac<=0) ){
    if(ms.empty()){
        ac+=( ( (oi[ind+1].ft-(ac+x) )/l )*l+((((oi[ind+1].ft-(ac+x) )%l)>0)?(l):(0))  );
        if(ac>0){break;}
        while(  (ind<n) && (oi[ind+1].ft<=(ac+x) ) ){
            ms.insert(oi[ind+1].sc); ind++;
        }
        auto it=ms.end(); it--;
        s+=*it; ms.erase(it);
        ac+=l;
        while(  (ind<n) && (oi[ind+1].ft<=(ac+x) ) ){
            ms.insert(oi[ind+1].sc); ind++;
        }
    }
    else{
                auto it=ms.end(); it--;
        s+=*it; ms.erase(it);
        ac+=l;
        while(  (ind<n) && (oi[ind+1].ft<=(ac+x) ) ){
            ms.insert(oi[ind+1].sc); ind++;
        }
    }
}
cout<<s;
return 0;
}