Cod sursa(job #3208774)

Utilizator AlexSerban21Serban Alexandru AlexSerban21 Data 29 februarie 2024 23:14:39
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
ifstream fin ("lupu.in");
ofstream fout ("lupu.out");
vector <pair <int,int>> v;
multiset <int> s;
multiset <int>::iterator it;
int n,x,l,d,nr,ii,i,t,ll;
long long suma;
int main()
{
    fin>>n>>x>>l;
    for (i=1; i<=n; i++)
    {
        fin>>d>>ll;
        nr=(x-d)/l;
        if (nr<=x)
            v.push_back ({nr,ll});
    }
    sort (v.begin(),v.end());
    i=ii=n-1;
    for (t=v[ii].first; t>=0; t--)
    {
        while (i>=0&&v[i].first>=t)
        {
            s.insert (v[i].second);
            i--;
        }
        if (!s.empty())
        {
            it=s.end();
            it--;
            suma=suma+*it;
            s.erase (it);
        }
    }
    fout<<suma;
    return 0;
}