Pagini recente » Cod sursa (job #2365122) | Cod sursa (job #2120887) | Cod sursa (job #3183320) | Cod sursa (job #1242706) | Cod sursa (job #2795560)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <queue>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
struct sheep {
int dist;
int amount;
inline bool operator < (const sheep& other) const
{
return this->amount < other.amount;
}
};
bool cmp(const sheep& a, const sheep& b)
{
return a.dist < b.dist;
}
priority_queue <sheep>myQueue;
sheep sheeps[100005];
int main() {
int n, dist, move;
fin >> n >> dist >> move;
for (int i = 0; i < n; i++) {
int x, y;
fin >> x >> y;
sheeps[i] = {x, y};
}
sort(sheeps + 0, sheeps + n, cmp);
int wave = 1;
int ans = 0;
int maxWave = dist / move;
int index = 0;
// for (int i = 0; i < n; i++)
// {
// cout << sheeps[i].dist << ' ' << sheeps[i].amount << '\n';
// }
// cout << '\n';
for (int i = 0; i < maxWave + 1; i++)
{
//cout << '\n' << "OK" << '\n';
while (sheeps[index].dist <= i * move && sheeps[index].dist <= dist && index < n)
{
//cout << sheeps[index].dist << ' ';
myQueue.push(sheeps[index]);
index++;
}
if (myQueue.empty())
{
continue;
}
//cout << "***" << myQueue.top().amount;
ans += myQueue.top().amount;
myQueue.pop();
}
fout << ans << '\n';
}