Cod sursa(job #841466)

Utilizator stoicatheoFlirk Navok stoicatheo Data 24 decembrie 2012 11:56:14
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;
struct oaie {
    int d,p;
} oi[100010];

bool cmp(oaie o1, oaie o2)
{
    return (o1.d > o2.d);
}

int main()
{
    int n,x,l,a;
    long long s(0);
    ifstream f("lupu.in");
    f >> n >> x >> l;
    for (int i = 1;i <= n;++i)
    {
        f >> a >> oi[i].p;
        oi[i].d = (x-a)/l + 1;
    }
    sort(oi+1, oi+n+1, cmp);


    priority_queue<int> fav;
    int  pas(oi[1].d), i(1);
    while (pas)
    {
        while (oi[i].d == pas && i <= n)
        {
            fav.push(oi[i].p);
            ++i;
        }
        if (!fav.empty())
        {
            s += fav.top();
            fav.pop();
        }
        --pas;
    }

    ofstream g("lupu.out");
    g << s << endl;


}