Cod sursa(job #1266612)

Utilizator andrei_diaconuAndrei Diaconu andrei_diaconu Data 18 noiembrie 2014 22:11:32
Problema Lupul Urias si Rau Scor 68
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <queue>
#include <algorithm>
#define NMax 100001
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
int n, x, l, i, j, el, k, ind, cantitate;
struct oaie
{
    int t;
    int lana;
}o[NMax];
priority_queue<int> H;
bool cmp(const oaie &o1, const oaie &o2)
{
    return o1.t > o2.t;
}
int main()
{
    f>>n>>x>>l;
    for (i=1; i<=n; i++) {
        f>>el;
        if (el<=x) {
            f>>o[++k].lana;
            o[k].t=(x-el)/l+1;
        }
    }
    sort (o+1, o+n+1, cmp);
    ind=1;
    k=1;
    for (i=o[1].t; i>=1; i--) {
        while (o[k].t==i) {
            H.push(o[k].lana);
            k++;
        }
        cantitate+=H.top();
        H.pop();
    }
    g<<cantitate;
    return 0;
}