Cod sursa(job #2851046)

Utilizator nubnubMeh Neh nubnub Data 17 februarie 2022 23:09:05
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <queue>
#include <algorithm>

using namespace std;

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

const int NMax = 1e5;

int N, X, L; long long Ans;
priority_queue <int> Q;

struct str{int d, val;} V[NMax + 5];
inline bool compare(str A, str B) { return A.d > B.d;}

int main()
{
    fin >> N >> X >> L;

    for(int i = 1; i <= N; i++)
        fin >> V[i].d >> V[i].val, V[i].d = ((V[i].d > X) ? 0 : ((X - V[i].d) / L) + 1);

    sort(V + 1, V + N + 1, compare);

    for(int k = V[1].d, i = 1; k > 0 && i > 0; k--)
    {
        while(V[i].d == k)
            Q.push(V[i++].val);

        if(!Q.empty())
            Ans += 1LL * Q.top(), Q.pop();
    }
    fout << Ans << '\n';

    fin.close();
    fout.close();

    return 0;
}