Cod sursa(job #1849972)

Utilizator AdrianGotcaAdrian Gotca AdrianGotca Data 17 ianuarie 2017 23:52:41
Problema Lupul Urias si Rau Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <bits/stdc++.h>

using namespace std;

struct str{
    int l,t;
}a[100005];
int tp,tc;
int cmp(str,str);
priority_queue <long long> q;
int n,dmax,l;
long long s;
int main(){
    freopen("lupu.in","r",stdin);
    freopen("lupu.out","w",stdout);
    cin>>n>>dmax>>l;
    for (int i=1;i<=n;i++){
        int d;
        cin>>d>>a[i].l;
        if (d>dmax){
            a[i].t=0;
        }
        else {
            a[i].t=(dmax-d)/l+1;
        }

    }
    sort(a+1,a+n+1,cmp);
    tp=0;
    long long i=1;
    while (i<=n){
        tp=a[i-1].t;
        tc=a[i].t;
        while (tp>tc&&!q.empty()){
            s+=q.top();
            q.pop();
            tp--;
        }
        while (a[i].t==tc&&i<=n){
            q.push(a[i].l);
            i++;
        }
    }
    cout<<s+q.top();
}

int cmp(str a,str b){
    return a.t>b.t;
}