Pagini recente » Cod sursa (job #3194294) | Cod sursa (job #1168714) | Cod sursa (job #1911740) | Cod sursa (job #2075818) | Cod sursa (job #2273691)
#include <fstream>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
const int MAXN = 100005;
#define d first
#define ct second
pair<int, int> oi[MAXN];
priority_queue<int> heap;
int main()
{
ifstream fin("lupu.in");
ofstream fout("lupu.out");
int n, x, l;
fin >> n >> x >> l;
for(int i = 1; i <= n; ++i){
fin >> oi[i].d >> oi[i].ct;
oi[i].d = (x - oi[i].d) / l;
}
sort(oi + 1, oi + n + 1);
long long tot = 0;
int pos = n;
x /= l;
while(x >= 0){
while(pos > 0 && oi[pos].d >= x){
heap.push(oi[pos].ct);
pos--;
}
if(!heap.empty()){
tot += heap.top();
heap.pop();
}
x--;
}
fout << tot;
return 0;
}