Cod sursa(job #2466496)

Utilizator stefantagaTaga Stefan stefantaga Data 2 octombrie 2019 13:13:26
Problema Lupul Urias si Rau Scor 28
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
struct wow
{
    long long  x,cost;
}v[100005];
bool compare (wow a,wow b)
{
    return a.x<b.x||(a.x==b.x&&a.cost<b.cost);
}
priority_queue <pair <long long ,long long > > h;
long long  n,i,dr,nr,l,d,init,x,ok;
long long sum;
int main()
{
    f>>n>>l>>x;
    for (i=1;i<=n;i++)
    {
        f>>v[i].x>>v[i].cost;
    }
    sort (v+1,v+n+1,compare);
    dr=n;
    nr=0;
    init=l;
    ok=0;
    l=l-x;
    while (ok==0)
    {
        while (dr>=1&&v[dr].x>l)
        {
            h.push({v[dr].cost,v[dr].x});
            dr--;
        }
        while (!h.empty()&&nr*x+h.top().second>init)
        {
            h.pop();
        }
        if (!h.empty())
        {
            sum=sum+h.top().first;
            h.pop();
            nr++;
        }
        if (dr==0&&h.empty())
        {
            break;
        }
        l=l-x;
    }
    g<<sum;
    return 0;
}