Pagini recente » Cod sursa (job #313727) | Cod sursa (job #665844) | Cod sursa (job #238965) | Cod sursa (job #772647) | Cod sursa (job #2838749)
#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) % l); ind < n; dist += l){
while(ind < n && o[ind].d >= dist && o[ind].d < dist + l)
heap.push(o[ind++]);
if(!heap.empty()){
ans += heap.top().a;
heap.pop();
}
}
g << ans;
g.close();
}