Cod sursa(job #3194952)

Utilizator Ruxandra009Ruxandra Vasilescu Ruxandra009 Data 19 ianuarie 2024 20:07:05
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <queue>
#include <algorithm>

using namespace std;

ifstream f("lupu.in");
ofstream g("lupu.out");

long long n, dist, scr, sumi;
pair<long long, long long> a[100005];
priority_queue<long long> H;

int main()
{
    f >> n >> dist >> scr;
    for(int i = 1; i <= n; i++)
    {
        long long x, y;
        f >> x >> y;

        a[i].first = (dist - x) / scr;
        a[i].second = y;
    }

    sort(a + 1, a + n + 1);

    long long x = a[n].first, p = n;
    while(x >= 0)
    {
        while(p && x <= a[p].first)
            H.push(a[p].second), p --;

        if(!H.empty())
            sumi += H.top(), H.pop();

        x --;
    }

    g << sumi;
    return 0;
}