Pagini recente » Cod sursa (job #682786) | Cod sursa (job #153166) | Cod sursa (job #1775673) | Cod sursa (job #117443) | Cod sursa (job #3267579)
#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++;
}
sum += PQ.top();
PQ.pop();
vechi = poz + 1;
} else {
sum += PQ.top();
PQ.pop();
}
cnt--;
}
fout << sum;
return 0;
}