Pagini recente » Cod sursa (job #2762550) | Cod sursa (job #1341191) | Cod sursa (job #140334) | Cod sursa (job #2445842) | Cod sursa (job #2838713)
#include <bits/stdc++.h>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
const int N = 1e5 + 1;
long long ans;
int n, x, l;
struct oaie{
int d, a;
bool operator < (oaie oa) const{
return a < oa.a;
}
}o[N];
priority_queue<oaie> heap;
bool cmp(oaie a, oaie b){
return a.d > b.d;
}
int main(){
f >> n >> x >> l;
for(int i = 0; i < n; i++)
f >> o[i].d >> o[i].a;
f.close();
sort(o, o + n, cmp);
int ind = 0;
while(ind < n && o[ind].d > x)
ind++;
for(int dist = x - l + 1; ind < n; dist -= l){
while(ind < n && o[ind].d >= dist)
heap.push(o[ind++]);
if(!heap.empty())
ans += heap.top().a;
while(!heap.empty())
heap.pop();
}
g << ans;
g.close();
}