Cod sursa(job #3359020)

Utilizator pkseVlad Bondoc pkse Data 22 iunie 2026 22:59:54
Problema Lupul Urias si Rau Scor 32
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <bits/stdc++.h>
#define int ll
using namespace std;
using ll = long long;

struct sheep {
    int d, v;
};

signed main() {
    ifstream cin("lupu.in");
    ofstream cout("lupu.out");
    cin.tie(0)->sync_with_stdio(0);
    
    int n, x, l; cin >> n >> x >> l;
    sheep a[n];
    for(int i = 0; i < n; i ++) {
        auto &[d, v] = a[i]; cin >> d >> v;
        d = (x - d) / l;
    }

    sort(a, a + n, [](sheep a, sheep b){
        return a.d > b.d;
    });

    int last = -1, ans = 0;
    priority_queue<int> pq;
    for(int i = 0; i < n && a[i].d >= 0; i ++) {
        if(last == -1) {
            last = a[i].d;
        } else if(last != a[i].d) {
            ans += pq.top();
            pq.pop();
            last = a[i].d;
        }
        pq.push(a[i].v);
    }
    ans += pq.top();
    cout << ans;
}