Cod sursa(job #2487485)

Utilizator AlexandruabcdeDobleaga Alexandru Alexandruabcde Data 4 noiembrie 2019 20:41:43
Problema Lupul Urias si Rau Scor 12
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <bits/stdc++.h>

using namespace std;

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

struct sheep
{
    int d, w;
};

sheep a[100005];

int n, x, l;
long long sol;

bool cmp (sheep a, sheep b)
{
    if (a.d > b.d) return false;

    return true;
}

priority_queue <int> q;

int main()
{
    f >> n >> x >> l;

    for (int i=1; i<=n; ++i)
    {
        f >> a[i].d >> a[i].w;

        if (a[i].d > x) a[i].d = 0;
        else a[i].d = ((x - a[i].d) / l + 1);
    }

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

    int ind = n;

    for (int val = a[n].d; val>=1; --val)
    {
        while (val == a[ind].d && ind > 0)
        {
            q.push(a[ind].w);
            ind--;
        }

        if (!q.empty())
        {
            sol = sol + 1LL * q.top();
            q.pop();
        }
        else val = a[ind].d + 1;
    }

    g << sol << '\n';
    return 0;
}