Cod sursa(job #2838749)

Utilizator CaptnBananaPetcu Tudor CaptnBanana Data 24 ianuarie 2022 15:56:16
Problema Lupul Urias si Rau Scor 72
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 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) % l); ind < n; dist += l){
        while(ind < n && o[ind].d >= dist && o[ind].d < dist + l)
            heap.push(o[ind++]);

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

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