Cod sursa(job #2820704)

Utilizator cristia_razvanCristia Razvan cristia_razvan Data 21 decembrie 2021 11:43:39
Problema Lupul Urias si Rau Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 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 + ((x - a[i].first) % L != 0);
    }
    sort(a + 1, a + n + 1);

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