Cod sursa(job #2821059)

Utilizator cristia_razvanCristia Razvan cristia_razvan Data 22 decembrie 2021 08:33:32
Problema Lupul Urias si Rau Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <bits/stdc++.h>
using namespace std;

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


int ans;
int n, x, L;
pair<int, int> a[100005];

priority_queue<int> q;
int main() {

    fin >> n >> x >> L;
    for(int i = 1; i <= n; ++i){
        fin >> a[i].first >> a[i].second;
        a[i].first = (x - a[i].first) / L;
    }
    sort(a + 1, a + n + 1);

    //for(int i = n; i >= 1; --i)
       // cout << a[i].first << " " << a[i].second << '\n';
    int i = n, ac = a[n].first;
    while(ac >= 0) {
        while(i > 0 && a[i].first >= ac) {
            q.push(a[i].second);
            --i;
        }
        if(!q.empty()) {
            ans += q.top();
            q.pop();
        }
        --ac;
    }
    fout << ans << '\n';
    fin.close();
    fout.close();
    return 0;
}