Cod sursa(job #3174313)

Utilizator Maftei_TudorMaftei Tudor Maftei_Tudor Data 24 noiembrie 2023 17:17:21
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
#include <queue>

#define fi first
#define sc second

using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
const int inf = (1 << 30) - 1 + (1 << 30);

int n, x, l;
long long ans;
priority_queue<pair<int, int>> que;

int main()
{
    in >> n >> x >> l;
    for(int i=1; i<=n; i++) {
        int d, a;
        in >> d >> a;
        int reps;
        if(x - d >= 0)
             reps = (x - d) % l ? (x - d) / l + 1 : (x - d) / l;
        else reps = -inf;
        que.push({-reps, a});
    }

    int timer = 0;
    while(!que.empty()) {
        if(timer <= -que.top().fi) {
            ans += que.top().sc;
            timer++;
        }

        que.pop();
    }

    out << ans;
    return 0;
}