Pagini recente » Cod sursa (job #1183141) | Cod sursa (job #2339348) | Cod sursa (job #2586252) | Cod sursa (job #1984434) | Cod sursa (job #2974747)
#include <fstream>
#include <queue>
#include <algorithm>
#include <queue>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
constexpr size_t LIM = 1e5 + 5;
int N, X, L, i, D, A;
pair<int, int> sheep[LIM];
priority_queue<int> pq;
long long ans;
int main() {
fin >> N >> X >> L;
for (i = 1; i <= N; ++i) {
fin >> D >> A;
sheep[i] = { D, A };
if (D <= X) ans += A;
}
if (X == 0) {
fout << ans;
goto program_end;
}
sort(sheep + 1, sheep + N + 1);
ans = 0;
for (int j = X % L, i = 1; j <= X; j += L) {
for (; i <= N && sheep[i].first <= j; ++i)
pq.push(sheep[i].second);
if (!pq.empty()) {
ans += pq.top();
pq.pop();
}
}
fout << ans;
program_end:
fin.close();
fout.close();
return 0;
}