Cod sursa(job #2629793)

Utilizator popoviciAna16Popovici Ana popoviciAna16 Data 22 iunie 2020 17:37:30
Problema Lupul Urias si Rau Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <queue>
using namespace std;

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

struct el
{
    int l, d;
    bool operator < (const el & alt) const
    {
        if (l == alt.l)
            return d > alt.d;
        return l < alt.l;
    }
};

priority_queue <el> p;

int main()
{
    int nr, n, x, l, i;
    int a, b;
    nr = 0;
    fin >> n >> x >> l;
    for (i = 1; i<=n; i++)
    {
        fin >> a >> b;
        p.push({b, a});
    }
    long long rasp = 0;
    while (p.empty() == 0)
    {
        if (p.top().d + 1ull*nr*l <= x)
        {
            rasp = rasp + p.top().l;
            nr++;
        }
        p.pop();
    }
    fout << rasp;
    return 0;
}