Cod sursa(job #2396111)

Utilizator vladstanciuVlad Stanciu vladstanciu Data 3 aprilie 2019 11:16:09
Problema Lupul Urias si Rau Scor 84
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <iostream>
#include <queue>
#include <fstream>
#include <algorithm>

using namespace std;

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

priority_queue <int> hip;

const int N=1000000;
long long n,i,sum=0,curent,x,l;

struct obiect{
    int t;
    int p;
}v[N];

int cmp(obiect a, obiect b)
{
    return a.t<b.t;
}

void golire()
{
    while(!hip.empty())
    {
        sum+=hip.top();
        hip.pop();
    }
}

int main()
{
    in>>n>>x>>l;
    for(i=1 ; i<=n ; i++)
    {
        in>>v[i].t>>v[i].p;
    }
    sort(v+1,v+n+1,cmp);
    int curent=0;
    for(i=n ; i>=1 ; i--)
    {
            if(v[i].t+curent<=x)
            {
                hip.push(-v[i].p);
                curent+=l;
            }
            else
            {
                if(hip.top()>-v[i].p)
                {
                    hip.pop();
                    hip.push(-v[i].p);
                }
            }
    }
    golire();
    out<<-sum;
    return 0;
}