Cod sursa(job #2823515)

Utilizator Andrei_ierdnANeculau Rares-Andrei Andrei_ierdnA Data 28 decembrie 2021 18:45:15
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <fstream>
#include <queue>
#include <algorithm>

using namespace std;

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

struct oaie
{
    long long t, w;
};

long long n, x, l, i, d, ct, s;
oaie oi[100100];
priority_queue<long long> wool;

bool comp(oaie o1, oaie o2)
{
    if (o1.t < o2.t)
        return true;
    return false;
}

int main()
{
    f >> n >> x >> l;
    for (i = 1; i <= n; i++) {
        f >> d;
        f >> oi[i].w;
        if (d <= x) {
            if (l == 0)
                oi[i].t = 100100;
            else {
                oi[i].t = (x - d) / l;
                if (oi[i].t > 100100)
                    oi[i].t = 100100;
            }
        }
        else
            oi[i].t = -1;
    }
    sort(oi + 1, oi + n + 1, comp);
    ct = oi[n].t;
    i = n;
    while (ct >= 0) {
        while (i >= 1 && oi[i].t == ct) {
            wool.push(oi[i].w);
            i--;
        }
        if (!wool.empty()) {
            s += wool.top();
            wool.pop();
        }
        ct--;
    }
    g << s;
    f.close();
    g.close();
    return 0;
}