Cod sursa(job #2464660)

Utilizator TudorCaloianCaloian Tudor-Ioan TudorCaloian Data 28 septembrie 2019 18:44:16
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;

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

int n, x, l, p;
ll ans;
vector < pair <int, int > > v;
multiset <ll> myset;
multiset <ll> :: iterator it;
int main()
{
    fin >> n >> x >> l;

    for(int i = 1; i <= n; i++)
    {
        int a, b;
        fin >> a >> b;
        int times;
        if(x < a) times = 0;
        else
            times = (x-a)/l+1;
        if(times)
            v.push_back(make_pair(times, b));
    }

    sort(v.begin(), v.end());

    for(int i = n-1; i >= 0; i--)
    {
        int time, cost;
        time = v[i].first;
        cost = v[i].second;
        myset.insert((ll)cost);
        p = time;
        if(i>0)
            while(v[i-1].first < p && !myset.empty())
            {
                it = myset.end();
                it--;
                ans += *it;
                myset.erase(it);
                p--;
            }
    }
        p = v[0].first;
       while(p && !myset.empty())
        {
            it = myset.end();
            it--;
            ans += *it;
            myset.erase(it);
            p--;
        }
    fout << ans;
    return 0;
}