Cod sursa(job #1466479)

Utilizator crysstyanIacob Paul Cristian crysstyan Data 29 iulie 2015 12:05:33
Problema Lupul Urias si Rau Scor 88
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#define NMAX 100001

using namespace std;

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

int i, n, x, l, j, tmax = -1;
long long ans = 0;

struct oaie
{
    int dist, lana;
};
oaie v[NMAX];

bool cmp(oaie a, oaie b)
{
    return a.dist < b.dist;
}

priority_queue < int > pq;

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

    for (i=1; i<=n; ++i)
    {
        f >> v[i].dist >> v[i].lana;

        if (l == 0) v[i].dist = 0;
            else
            v[i].dist = (x - v[i].dist) / l + 1;
        tmax = max(tmax, v[i].dist);
    }

    i = n;
    sort(v + 1, v + n + 1, cmp);

    for (j = tmax; j >= 1; -- j)
    {
        while (v[i].dist == j)
               pq.push(v[i].lana), i--;

        if (pq.empty())
            j = v[i].dist;
        else
            {
                ans += (long long) pq.top();
                if (pq.size())
                pq.pop();
            }
    }

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