Pagini recente » Cod sursa (job #1611838) | Cod sursa (job #2511227) | Cod sursa (job #2666648) | Cod sursa (job #5917) | Cod sursa (job #3267580)
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
vector<pair<int, int>> V;
priority_queue<int> PQ;
int main() {
int n, x, l;
fin >> n >> x >> l;
int maxim = 0;
for (int i = 1; i <= n; ++i) {
int d, a;
fin >> d >> a;
if (d <= x) {
int ind = (x - d) / l + 1;
V.push_back({ind, a});
maxim = max(maxim, ind);
}
}
sort(V.begin(), V.end(), greater<pair<int, int>>());
int cnt = maxim;
int vechi = 0;
long long sum = 0;
while (cnt) {
int poz = vechi;
if (V[poz].first == cnt) {
PQ.push(V[poz].second);
while (V[poz + 1].first == V[vechi].first) {
PQ.push(V[poz + 1].second);
poz++;
}
if (PQ.size()) {
sum += PQ.top();
PQ.pop();
}
vechi = poz + 1;
} else {
if (PQ.size()) {
sum += PQ.top();
PQ.pop();
}
}
cnt--;
}
fout << sum;
return 0;
}