Cod sursa(job #3125860)

Utilizator RORO123bBarbulescu Robert RORO123b Data 4 mai 2023 18:14:37
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <fstream>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

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

const int N=1e5;

int main()
{
    int n,x,l;
    fin>>n>>x>>l;
    vector<pair<int,int>> v(n);
    for(int i=0;i<n;i++)
        fin>>v[i].first>>v[i].second;
    sort(v.begin(),v.end(),greater<pair<int,int>>());
    priority_queue<int,vector<int>,greater<int>> h;
    int t_c=0;
    long long l_totala=0;
    for(auto p:v)
    {
        if(p.first + (long long)t_c * l<=x)
            {
                h.push(p.second);
                l_totala+=p.second;
                t_c++;
            }
        else
            {
                if(!h.empty() && p.second>h.top())
                {
                    l_totala+=p.second-h.top();
                    h.pop();
                    h.push(p.second);
                }
            }
    }
    fout<<l_totala<<'\n';
    return 0;
}