Cod sursa(job #2461347)

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

using namespace std;

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

int n, x, l, ans;
vector < pair <int, int > > v;
set <int> check;
set <int> :: iterator it;
int main()
{
    fin >> n >> x >> l;

    for(int i = 1; i <= 100000; i++)
        check.insert(-i);
    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));
    }

    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;
        if(t > 100000) t = 100000;
        it = check.lower_bound(-t);
        int x= *it;
        if(it != check.end())
        {
            ans += cost;
            check.erase(x);
        }

    }
    fout << ans;
    return 0;
}