Cod sursa(job #3273284)

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

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

class comp {
public:
    bool operator()(pair<int, int> a, pair<int, int> b) {
        if (a.first + dist + l > x && b.first + dist + l <= x) {
            return false;
        } else if (a.first + dist + l <= x && b.first + dist + l > x) {
            return true;
        } else {
            if (a.first + dist + l > x && b.first + dist + l > x) {
                return a.second < b.second;
            }
            if (a.first == b.first) {
                return a.second < b.second;
            }
        }
    }
};

priority_queue<pair<int, int>, vector<pair<int, int>>, comp> 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;
    while (!q.empty()) {
        if (x >= q.top().first + dist) {
            ans += q.top().second;
            dist += l;
        }
        q.pop();
    }
    cout << ans;
}