Cod sursa(job #3273313)

Utilizator Barbu_MateiBarbu Matei Barbu_Matei Data 1 februarie 2025 16:28:20
Problema Lupul Urias si Rau Scor 28
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>
using namespace std;

int n, x, l;
long long dist = 0;

priority_queue<pair<int, int>> q;

int main() {
    ifstream cin("lupu.in");
    ofstream cout("lupu.out");
    cin >> n >> x >> l;
    for (int i = 1; i <= n; ++i) {
        int d, c;
        cin >> d >> c;
        q.push({d, c});
    }
    long long ans = 0;
    int maxVal = 0;
    while (!q.empty()) {
        if (q.top().first + dist + l > x && q.top().first + dist <= x) {
            maxVal = max(maxVal, q.top().second);
        }
        if (q.top().first + dist + l <= x) {
            ans += maxVal;
            maxVal = q.top().second;
            dist += l;
        }
        q.pop();
    }
    cout << ans + maxVal;
}