Cod sursa(job #2069677)

Utilizator tifui.alexandruTifui Ioan Alexandru tifui.alexandru Data 18 noiembrie 2017 18:24:08
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <bits/stdc++.h>
#define Nmax 100001
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
pair <int,int> v[Nmax];
priority_queue <int> pq;
inline bool cmp(const pair <int,int> &x, const pair <int,int> &y)
{
    if(x.first==y.first)
        return x.second>y.second;
    else return x.first>y.first;
}
int main()
{
    int n,x,l,i,lsh,rsh,N=0;
    f>>n>>x>>l;
    for(i=1;i<=n;i++)
    {
        f>>lsh>>rsh;
        if(lsh<=x) v[++N]={(x-lsh)/l,rsh};
    }
    sort(v+1,v+N+1,cmp);
    long long ans=0;
    int j=1;
    for(i=v[1].first;i>=0;i--)
    {
        for(;j<=N and i==v[j].first;)
        {
                pq.push(v[j].second);
                j++;
        }
        if(!pq.empty())
            {
                ans+=1LL*pq.top();
                pq.pop();
            }
    }
    g<<ans;

    return 0;
}