Cod sursa(job #2039594)

Utilizator LauraNaduLaura Nadu LauraNadu Data 14 octombrie 2017 18:06:05
Problema Lupul Urias si Rau Scor 72
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include<fstream>
#include<queue>
#include<algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
struct oaie {
    int dist;
    int puf;
} a[100002];
bool cmp(oaie x, oaie y)
{
    return x.dist>y.dist;
}
int n, d, l, k, s, i, ii, t[100002], tmax;
priority_queue <int, vector<int> > heap;
int main()
{
    f>>n>>d>>l;
    for(i=1;i<=n;i++)
    {
        f>>a[i].dist>>a[i].puf;
        if(a[i].dist>d)
        {
            a[i].dist=2147483648;
            continue;
        }
        if(l!=0)
        {
            a[i].dist=(d-a[i].dist)/l+1;
            if(a[i].dist>tmax)
            {
                tmax=a[i].dist;
                continue;
            }
        }
        if(a[i].dist<0)
            a[i].dist=2147483648;
    }
    sort(a+1, a+n+1, cmp);
    ii=1;
    while(a[ii].dist!=tmax)
        ii++;
    for(i=tmax;i>0;i--)
    {
        for(;a[ii].dist==i;ii++)
            heap.push(a[ii].puf);
        s+=heap.top();
        heap.pop();
    }
    /*for(i=1;i<=n;i++)
        g<<a[i].t<<" ";*/
    g<<s;
    return 0;
}