Cod sursa(job #2506829)

Utilizator radugheoRadu Mihai Gheorghe radugheo Data 8 decembrie 2019 20:23:18
Problema Lupul Urias si Rau Scor 32
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <bits/stdc++.h>

using namespace std;

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

long long n, x, l, i, d, a, m, sol;

pair <long long, long long> v[100005];

set <long long> es;

int main(){
    fin >> n >> x >> l;
    for (i=1; i<=n; i++){
        fin >> d >> a;
        if (d <= x){
            v[++m] = {(x-d)/l + 1, a};
        }
    }
    sort (v + 1, v + m + 1);
    for (i=v[m].first; i>=1; i--){
        while (v[m].first == i && m > 0){
            es.insert (-v[m].second);
            m--;
        }
        if (!es.empty()){
            sol += *es.begin();
            es.erase (es.begin());
        }
    }
    fout << -sol;
    return 0;
}