Pagini recente » Cod sursa (job #1199454) | Cod sursa (job #2647026) | Cod sursa (job #53326) | Cod sursa (job #182096) | Cod sursa (job #3178017)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <queue>
#define int long long
using namespace std;
const int nmax = 1e5;
pair<int, int> a[5 + nmax];
signed main() {
ifstream fin("lupu.in");
ofstream fout("lupu.out");
int n, x, l;
fin >> n >> x >> l;
for (int i = 1; i <= n; i++) {
int d;
fin >> d >> a[i].first;
a[i].second = (x - d) / l;
}
sort(a + 1, a + n + 1, [&](pair<int, int> a, pair<int, int> b) {
if (a.second == b.second)
return a.first < b.first;
return a.second < b.second;
});
priority_queue<int> pq;
int ptr = n, ans = 0;
for (int i = a[n].second; i >= 0; i--) {
while (ptr >= 1 && a[ptr].second >= i) {
pq.push(a[ptr].first);
ptr--;
}
if (!pq.empty()) {
ans += pq.top();
pq.pop();
}
}
fout << ans << '\n';
return 0;
}