Cod sursa(job #2582134)

Utilizator Senth30Denis-Florin Cringanu Senth30 Data 16 martie 2020 14:04:23
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <bits/stdc++.h>
#define MAX 131072
#define MOD 666013
#define fx first
#define fy second

using namespace std;
const int NMAX = 100010;

int N, K, L;
long long ans;
pair <int, int> v[NMAX];
priority_queue <int> heap;

int main(){

    freopen("lupu.in", "r", stdin);
    freopen("lupu.out", "w", stdout);

    scanf("%d%d%d", &N, &L, &K);
    for(int i = 1; i <= N; i++)
        scanf("%d%d", &v[i].fx, &v[i].fy);
    sort(v + 1, v + N + 1);
    for(int i = 1, dr = 0; i <= N && dr <= L; dr += K){
        while(i <= N && v[i].fx <= dr){
            heap.push(v[i].fy);
            i++;
        }
        if(!heap.empty()){
            ans = ans + heap.top();
            heap.pop();
        }
    }
    printf("%lld", ans);


    return 0;
}