Cod sursa(job #1074753)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 7 ianuarie 2014 22:16:19
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<fstream>
#include<queue>
#include<algorithm>

using namespace std;

struct casa{
            int d,c;
           } a[100005];

priority_queue <int> h;

long long sol,n,x,l,dist,i;

bool cmp (const casa &a,const casa &b)
{
    if(a.d<b.d)
        return 1;
    return 0;
}

int main ()
{
    ifstream f("lupu.in");
    ofstream g("lupu.out");
    f>>n>>x>>l;
    for(i=1;i<=n;i++)
      f>>a[i].d>>a[i].c;
    sort(a+1,a+n+1,cmp);
    for(dist=0,i=1;dist<=x&&i<=n;dist+=l)
    {
        for(;i<=n&&a[i].d<=dist;i++)
            h.push(a[i].c);
        if(h.size())
        {
            sol+=h.top();
            h.pop();
        }
    }
    g<<sol<<"\n";
    return 0;
}