Cod sursa(job #2647423)

Utilizator CONFUSION@@@@@ @@@ CONFUSION Data 4 septembrie 2020 15:51:29
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul II Marime 0.69 kb
#include <bits/stdc++.h>
using namespace std;

int main () {
    freopen("lupu.in", "r", stdin);
    freopen("lupu.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, x, l;
    cin >> n >> x >> l;

    vector <pair <int, int>> v(n);
    for (auto &it: v)
        cin >> it.first >> it.second;
    sort(v.begin(), v.end());

    priority_queue <int> PQ;
    long long ans = 0;
    
    int i = 0, d;
    for (d = 0; d <= x; d += l) {
        while (i < n && v[i].first <= d)
            PQ.push(v[i++].second);
        
        if (!PQ.empty()) {
            ans += PQ.top();
            PQ.pop();
        }
    }

    cout << ans;
    return 0;
}