Cod sursa(job #2918270)

Utilizator Botnaru_VictorBotnaru Victor Botnaru_Victor Data 10 august 2022 19:19:40
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <bits/stdc++.h>
#define nmax 100003
using namespace std;

ifstream f("lupu.in");
ofstream g("lupu.out");

vector<int> v[nmax];
int n,x,l;
int h[nmax],k;
int getpoz(const int &nr)
{
    return max(0,(x-nr)/l+1);
}

bool cmp(const int &a, const int &b)
{
    return a>b;
}
int main()
{
    f>>n>>x>>l;
    int a,b;
    int mx=0;
    for(int i=0;i<n;i++)
    {
        f>>a>>b;
        a=getpoz(a);
        v[a].push_back(b);
        mx=max(mx,a);
    }
    for(int i=1;i<=mx;i++)
    {
        sort(v[i].begin(),v[i].end(),cmp);
        for(int j=0;j<min(i,(int)(v[i].size()));j++)
        {
            //cout<<i<<','<<j<<','<<v[i][j]<<'\n';
            if(k<i)
            {
                h[k++]=v[i][j];
                push_heap(h,h+k,cmp);
            }
            else if(v[i][j]>h[0])
            {
                pop_heap(h,h+k,cmp);
                h[k-1]=v[i][j];
                push_heap(h,h+k,cmp);
            }
        }
    }
    long long ans=0;
    for(int i=0;i<k;i++)
    {
        //cout<<h[i]<<' ';
        ans+=(long long)(h[i]);
    }
    g<<ans;
    return 0;
}