Pagini recente » Cod sursa (job #2883340) | Cod sursa (job #67745) | Cod sursa (job #2912040) | Rating Rusu Denis (RusuDenis) | Cod sursa (job #3267568)
#include <fstream>
#include <queue>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
#define NMAX 100005
priority_queue<int> PQ[NMAX];
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;
PQ[ind].push(a);
maxim = max(maxim, ind);
}
}
int poz = maxim;
long long sum = 0;
while (poz) {
if (PQ[poz].size()) {
if (PQ[maxim].size()) {
if (PQ[poz].top() > PQ[maxim].top()) {
sum += PQ[poz].top();
PQ[poz].pop();
if (PQ[poz].top() > PQ[maxim].top()) {
maxim = poz;
}
} else {
sum += PQ[maxim].top();
PQ[maxim].pop();
for (int i = poz; i <= maxim; ++i) {
if (PQ[i].top() > PQ[maxim].top()) {
maxim = i;
}
}
}
} else {
sum += PQ[poz].top();
PQ[poz].pop();
maxim = poz;
}
} else {
if (PQ[maxim].size()) {
sum += PQ[maxim].top();
PQ[maxim].pop();
for (int i = poz; i <= maxim; ++i) {
if (PQ[i].size() && PQ[i].top() > PQ[maxim].top()) {
maxim = i;
}
}
}
}
poz--;
}
fout << sum;
return 0;
}