Cod sursa(job #1901370)

Utilizator GoogalAbabei Daniel Googal Data 3 martie 2017 21:52:14
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <algorithm>
#include <queue>
#define nmax 100001

using namespace std;

ifstream fin("lupu.in");
ofstream fout("lupu.out");

struct sheep
{
    long long dist;
    long long lana;
};

long long n,d,l,maxx,cost;
sheep v[nmax];

priority_queue < long long > behehe;

bool cmp(sheep a, sheep b)
{
    return a.dist>b.dist;
}

int main()
{
    int i;
    fin>>n>>d>>l;

    for(i=1;i<=n;i++)
    {
        fin>>v[i].dist>>v[i].lana;
        v[i].dist=(d - v[i].dist) / l + 1 ;
        maxx=max(maxx,v[i].dist);
    }

    sort(v+1,v+n+1,cmp);

    i=1;
    while(maxx>0)
    {
        while(v[i].dist==maxx)
        {
            behehe.push(v[i].lana);
            i++;
        }

        if(!behehe.empty())
        {
            cost+=behehe.top();
            behehe.pop();
        }
        maxx--;
    }

    fout<<cost;
    fin.close();
    fout.close();
    return 0;
}