Cod sursa(job #2750188)

Utilizator As932Stanciu Andreea As932 Data 10 mai 2021 09:55:18
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

const int nmax = 1e5 + 5;

struct sh {
    int dt, lana;
    bool operator < (const sh &sth) const {
        return dt < sth.dt;
    }
};

sh v[nmax];
priority_queue <int> pq;
int n, x, l, m;
ll rsp;

void read(){
    fin >> n >> x >> l;

    for(int i = 1; i <= n; i++){
        int d, a;

        fin >> d >> a;

        if(d <= x)
            v[++m] = {(x - d) / l, a};
    }
}

void solve(){
    int i = m, d = n - 1;
    while(i >= 1){
        while(i >= 1 && d == v[i].dt)
            pq.push(v[i--].lana);

        d--;

        if(!pq.empty()){
            rsp += pq.top();
            pq.pop();
        }
    }

    fout << rsp;
}

int main()
{
    read();
    sort(v + 1, v + m + 1);
    solve();

    return 0;
}