Cod sursa(job #2059699)

Utilizator mihai.alphamihai craciun mihai.alpha Data 7 noiembrie 2017 14:20:55
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

#define fi first
#define se second

struct cmp  {
    bool operator ()  (int a, int b)  {
        return a < b;
    }
};

int N, X, L, newn;
pair <int, int> v[MAXN];
priority_queue <int, vector <int>, cmp> pq;

int main()  {
    freopen("lupu.in", "r", stdin);
    freopen("lupu.out", "w", stdout);
    scanf("%d%d%d", &N, &X, &L);
    for(int i = 1;i <= N;i++)  {
        int fii, see;
        scanf("%d%d", &fii, &see);
        /*     distanta   lana
    */
    //la fel ca procesor
        if(fii <= X)   {
            v[++newn] = {(X - fii) / L, see};
        }
    }
    sort(v + 1, v + N + 1);
    long long tot = 0LL, j = N;
    for(int i = v[N].fi;i >= 0;i--)  {
        while(j >= 1 && i == v[j].fi)  {
            pq.push(v[j].se);
            j--;
        }
        if(pq.size())
            tot += 1LL * pq.top(), pq.pop();
    }
    cout << tot;
    return 0;
}