Cod sursa(job #1878265)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 13 februarie 2017 23:21:38
Problema Lupul Urias si Rau Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <bits/stdc++.h>

#define ll long long
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");

ll n,x,l,D,lana,d;
multiset<pair<ll,ll> > H;

int main()
{
    f >> n >> l >> D;
    for(ll i = 1; i <= n; ++i){
        f >> d >> lana;
        if(d <= l){
            H.insert(make_pair(-lana,d));
        }
    }
    ll ans = 0;
    while(!H.empty()){
        ll La = (*H.begin()).first;
        ll Di = (*H.begin()).second;

        while(Di > l && !H.empty()){
            H.erase(H.begin());
            La = (*H.begin()).first;
            Di = (*H.begin()).second;
        }
        if(H.empty())
            break;

        ans += -La;
        l -= D;
        H.erase(H.begin());
    }
    g << ans << '\n';

    return 0;
}