Pagini recente » Cod sursa (job #1514155) | Cod sursa (job #113026) | Cod sursa (job #2444866) | Cod sursa (job #1797032) | Cod sursa (job #2838766)
#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) - l + 1; 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();
}