Cod sursa(job #1466461)

Utilizator crysstyanIacob Paul Cristian crysstyan Data 29 iulie 2015 11:42:26
Problema Lupul Urias si Rau Scor 48
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 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, ans = 0, timp[NMAX], j, tmax = -1;

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

priority_queue < int > pq;

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

    for (i=1; i<=n; ++i)
    {
        f >> v[i].dist >> v[i].lana;
        timp[i] = (x - v[i].dist) / l;
        tmax = max(tmax, timp[i]);
    }

    for (j = tmax; j >= 0; -- j)
    {
        for (i = 1; i <= n; ++ i)
            if (timp[i] == j)
                pq.push(v[i].lana);

        ans += pq.top();
        pq.pop();
    }

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