Cod sursa(job #2412366)

Utilizator mihnea.anghelMihnea Anghel mihnea.anghel Data 22 aprilie 2019 10:26:11
Problema Lupul Urias si Rau Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <set>
#include <algorithm>
#define umom first
#define lana second

using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");

multiset <int> S;
multiset <int>::iterator it;

pair < int, int > v[100009];

int n,x,l,i,k,sol,poz,d,L;

int main()
{
    f>>n>>x>>L;
    for( i=1; i <= n; i++ ){
        f>>d>>l;
        if ( d <= x ) v[++k].lana=l, v[k].umom = 1 + (x-d)/L;
    }
    sort (v+1, v+k+1);
    poz=k;
    for ( i=v[k].umom; i>=1; i-- ){

        while ( poz >= 1  && v[poz].umom==i)
            S.insert ( v[poz].lana ), poz--;

        if ( !S.empty() ){
            it=S.end(); it--;
            sol += *it;
            S.erase(it);
        }
    }
    g<<sol;
    return 0;
}