Cod sursa(job #1463402)

Utilizator lflorin29Florin Laiu lflorin29 Data 20 iulie 2015 21:31:49
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <iostream>
#include <queue>
#include <algorithm>
#include <fstream>
using namespace std;

ifstream fin ("lupu.in");
ofstream fout ("lupu.out");

const int wolf = 100000;
long long n, x, l, AF;

#define F first
#define S second
vector < pair <long long, long long> > lup;
priority_queue <long long> RP;

//auto Comp = [](const pair <int, int> &a, const pair <int, int> &b) {
 //   return (a.F > b.F);
//};


int main(){
    fin >> n >> x >> l;
    lup.resize(n);
    for (int i = 0; i < n; i++)
        fin >> lup[i].F >> lup[i].S;
    sort(lup.begin(), lup.end());
    long long T = (x - lup[0].F) / l;
    int p = 0;
    //fout << (1 << 31) - 1 << "\n" ;
    for (; T >= 0; -- T ) {
        while (p < n and (x - lup[p].F) / l == T )
              RP.push(lup[p ++ ].S);
        if (!RP.empty())
                AF += RP.top(), RP.pop();
    }
    fout << AF;
    return 0;
}