Cod sursa(job #2470667)

Utilizator PredescuSebastianIonPredescu Sebastian Ion PredescuSebastianIon Data 9 octombrie 2019 17:38:59
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
struct ceva
{
    int distanta,lana;
} a[100003];
int n,x,l;
long long sol;
priority_queue <int> q;
bool cmp(ceva a,ceva b)
{
    return a.distanta>=b.distanta;
}
int main()
{
    f>>n>>x>>l;
    for(int i=1;i<=n;i++)
    {
        f>>a[i].distanta>>a[i].lana;
        if(x<a[i].distanta)a[i].distanta=0;
        else a[i].distanta=((x-a[i].distanta)/l)+1;
    }
    sort(a+1,a+n+1,cmp);
    int k=a[1].distanta;
    for(int i=1;i<=n && k;k--)
    {
        while(k==a[i].distanta && i<=n)
        {
            q.push(a[i].lana);
            i++;
        }
        if(!q.empty())
        {
            sol+=1LL*q.top();
            q.pop();
        }
        else k=a[i].distanta+1;
    }
    g<<sol<<'\n';
    return 0;
}