Cod sursa(job #2262631)

Utilizator SchnitzelMannPavaloiu Gabriel SchnitzelMann Data 17 octombrie 2018 17:30:18
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
pair<int,int> a[100002];
int h[100002];
int main()
{
    int n,x,l,m=0,i,j;
    long long s=0;
    in>>n>>x>>l;
    for(i=0;i<n;i++)
        in>>a[i].x>>a[i].y;
    sort(a,a+n);
    for(i=x/l,j=0;i>=0;i--)
    {
        while(j<n&&a[j].x+i*l<=x)
        {
            h[++m]=a[j++].y;
            push_heap(h+1,h+m+1);
        }
        if(m)
        {
            s+=1LL*h[1];
            pop_heap(h+1,h+m+1);
            m--;
        }
    }
    out<<s;
    return 0;
}