Cod sursa(job #1878316)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 14 februarie 2017 00:23:33
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>

#define ll long long
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");

const int NMax = 100002;

int n,x,L,D,lana,d,ans,mx;
multiset<int> H;

struct stat{
    int x,y,nr;
};

stat a[NMax];

bool cmp(stat x, stat y){
    return (x.nr > y.nr);
}
int main()
{
    f >> n >> L >> D;
    for(int i = 1; i <= n; ++i){
        f >> a[i].x >> a[i].y;
        a[i].nr = (L - a[i].x) / D;
        mx = max(mx,a[i].nr);
    }
    sort(a + 1, a + 1 + n, cmp);

    ll ans = 0;
    int c = 1;
    for(int i = mx; i >= 0; --i){
        while(a[c].nr == i){
            H.insert(-a[c].y);
            c++;
        }

        if(!H.empty()){
            ans += 1LL*(-(*H.begin()));
            H.erase(H.begin());
        }
    }
    g << ans << '\n';
    return 0;
}