Pagini recente » Cod sursa (job #2723987) | Cod sursa (job #1852962) | Cod sursa (job #1075012) | Cod sursa (job #2182065) | Cod sursa (job #2855022)
#include <fstream>
#include <algorithm>
#include <queue>
const int MAX_N = 1e5;
std::pair<int, int> a[1 + MAX_N];
std::priority_queue<int> pq;
bool cmp(std::pair<int, int> a, std::pair<int, int> b) {
return a.first > b.first;
}
int main() {
std::ifstream fin("lupu.in");
std::ofstream fout("lupu.out");
int n, x, l;
fin >> n >> x >> l;
for (int i = 1; i <= n; i++) {
fin >> a[i].first >> a[i].second;
}
std::sort(a + 1, a + n + 1, cmp);
int answer = 0, cnt = 0;
for (int i = 1; i <= n; i++) {
int dist = a[i].first + cnt * l;
if (dist <= x) {
answer += a[i].second;
pq.push(-a[i].second);
cnt++;
} else if (!pq.empty() && a[i].second > -pq.top()) {
answer += a[i].second;
answer -= -pq.top();
pq.pop();
pq.push(-a[i].second);
}
}
fout << answer;
return 0;
}