Cod sursa(job #3208815)

Utilizator AlexSerban21Serban Alexandru AlexSerban21 Data 1 martie 2024 10:03:12
Problema Lupul Urias si Rau Scor 84
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 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;
        if (d>x)
            continue;
        nr=(x-d)/l;
        v.push_back ({nr,ll});
    }
    sort (v.begin(),v.end());
    if (!v.empty ())
    {
        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;
}