Cod sursa(job #2525787)

Utilizator Rares31100Popa Rares Rares31100 Data 17 ianuarie 2020 20:15:02
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>
#define Dist first
#define Lana second

using namespace std;

ifstream in("lupu.in");
ofstream out("lupu.out");

int n,x,l;
pair <int,int> a[100001];
priority_queue <int,vector<int>,greater<int>> c;

int main()
{
    in>>n>>x>>l;

    for(int i=1;i<=n;i++)
        in>>a[i].Dist>>a[i].Lana;

    sort(a+1,a+n+1);

    int i=n;
    while(i && a[i].Dist>x)
        i--;

    for(;i;i--)
        if(a[i].Dist<=x)
        {
            c.push(a[i].Lana);
            x-=l;
        }
        else if(c.top()<a[i].Lana)
        {
            c.pop();
            c.push(a[i].Lana);
        }

    long long sum=0;

    while(!c.empty())
    {
        sum+=(long long)c.top();
        c.pop();
    }

    out<<sum;

    return 0;
}