Cod sursa(job #3360010)

Utilizator serbanbBrindescu Serban serbanb Data 7 iulie 2026 17:14:30
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

ifstream fin("lupu.in");
ofstream fout("lupu.out");

int n,x,l;
vector<pair<int, int>> sheep;
priority_queue<int> heap;
long long int ans;

void read()
{
    fin >> n >> x >> l;
    for(int i = 0; i < n; ++i){
        int d,a;
        fin >> d >> a;
        int bucket = (x - d) / l;
        sheep.push_back(make_pair(bucket, a));
    }
}

void solve()
{
    sort(sheep.begin(), sheep.end());
    for(int i = sheep.size() - 1; i >= 0; --i){
        if(i < sheep.size() - 1 && sheep[i].first != sheep[i + 1].first){
            if(!heap.empty()){
                ans += heap.top();
                heap.pop();
            }
        }
        heap.push(sheep[i].second);
    }
    if(!heap.empty()){
        ans += heap.top();
        heap.pop();
    }
    fout << ans;
}

int main()
{
    read();
    solve();
    return 0;
}