Cod sursa(job #2412365)

Utilizator mihnea.anghelMihnea Anghel mihnea.anghel Data 22 aprilie 2019 10:25:02
Problema Lupul Urias si Rau Scor 96
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#include <set>
#include <algorithm>

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

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

struct potae{
    int lana;
    int umom;
} v[100009];

bool cmp (const potae &a, const potae &b){
    return ( a.umom > b.umom );
}

long long 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, cmp);
    poz=1;
    for ( i=v[1].umom; i>=1; i-- ){

        while ( poz <= k && 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;
}