Cod sursa(job #2461349)

Utilizator TudorCaloianCaloian Tudor-Ioan TudorCaloian Data 25 septembrie 2019 14:18:50
Problema Lupul Urias si Rau Scor 68
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <bits/stdc++.h>

using namespace std;

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

int n, x, l, ans, tmax;
vector < pair <int, int > > v;
vector <int> check;
vector <int> :: 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(b, times));
        tmax = max(tmax, times);
    }

    while(tmax >= 1)
    {
        check.push_back(-tmax);
        tmax--;
    }
    sort(v.begin(), v.end());
    for(int i = v.size()-1; i >= 0; i--)
    {
        int cost, t;
        cost = v[i].first;
        t = v[i].second;

        it = lower_bound(check.begin(), check.end(), -t);
        int x= *it;
        if(it != check.end())
        {
            ans += cost;
            check.erase(it);
        }

    }
    fout << ans;
    return 0;
}