Cod sursa(job #2838713)

Utilizator CaptnBananaPetcu Tudor CaptnBanana Data 24 ianuarie 2022 14:54:46
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("lupu.in");
ofstream g("lupu.out");

const int N = 1e5 + 1;
long long ans;
int n, x, l;
struct oaie{
    int d, a;
    bool operator < (oaie oa) const{
        return a < oa.a;
    }
}o[N];
priority_queue<oaie> heap;

bool cmp(oaie a, oaie b){
    return a.d > b.d;
}

int main(){
    f >> n >> x >> l;
    for(int i = 0; i < n; i++)
        f >> o[i].d >> o[i].a;

    f.close();
    sort(o, o + n, cmp);
    int ind = 0;
    while(ind < n && o[ind].d > x)
        ind++;

    for(int dist = x - l + 1; ind < n; dist -= l){
        while(ind < n && o[ind].d >= dist)
            heap.push(o[ind++]);

        if(!heap.empty())
            ans += heap.top().a;

        while(!heap.empty())
            heap.pop();
    }

    g << ans;
    g.close();
}