Cod sursa(job #3332307)

Utilizator AlexandruTigauTigau Alexandru AlexandruTigau Data 6 ianuarie 2026 00:37:48
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
priority_queue<int, vector<int>, greater<int>> pq;
pair<int, int> a[100005];
int main()
{
    int n, x, l;
    f >> n >> x >> l;
    for(int i = 1; i <= n; i++)
    {
        int d, c;
        f >> d >> c;
        if(d > x) {
            n--, i--;
            continue;
        }
        a[i] = {1 + (x - d) / l, c};
    }
    sort(a + 1, a + n + 1);
    long long ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ans += a[i].second;
        pq.push(a[i].second);
        if(pq.size() > a[i].first) {
            ans -= pq.top();
            pq.pop();
        }
    }
    g << ans;
    return 0;
}