Cod sursa(job #1274347)

Utilizator andrei_diaconuAndrei Diaconu andrei_diaconu Data 23 noiembrie 2014 18:48:35
Problema Lupul Urias si Rau Scor 96
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <queue>
#include <algorithm>
#define NMax 100100
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
int n, x, l, i, j, el, k, ind;
long long 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+k+1, cmp);
    ind=1;
    int sz=k;
    k=1;
    for (i=o[1].t; i>=1; i--) {
        while (o[k].t==i && k < sz) {
            H.push(o[k].lana);
            k++;
        }
        if (!H.empty()) {
            cantitate+=1LL*H.top();
            H.pop();
        }
    }
    g<<cantitate;
    return 0;
}