Pagini recente » Cod sursa (job #1283898) | Cod sursa (job #678226) | Cod sursa (job #1145787) | Cod sursa (job #2334438) | Cod sursa (job #2286725)
#include <bits/stdc++.h>
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
int main() {
ios::sync_with_stdio(false); in.tie(0); out.tie(0);
int n, x ,l; in >> n >> x >> l;
vector< pair< int, int > > oi(n);
for(auto &it: oi) in >> it.first >> it.second;
sort(oi.begin(), oi.end(), [&](const pair< int, int > &a, const pair< int, int > &b) {
return a.first > b.first;
});
int ans = 0;
int lastDist = x - l;
priority_queue< int > pq;
for(int i = 0; i < n; ++i) {
if(oi[i].first <= x && oi[i].first > lastDist) {
pq.push(oi[i].second);
} else {
ans += pq.top();
x = lastDist;
lastDist -= l;
while(!pq.empty()) {
pq.pop();
}
--i;
}
}
if(!pq.empty()) {
ans += pq.top();
}
out << ans << "\n";
in.close(); out.close();
return 0;
}