Pagini recente » Cod sursa (job #2790665) | Cod sursa (job #3133115) | Cod sursa (job #3165314) | Cod sursa (job #3004014) | Cod sursa (job #1586622)
#include <fstream>
#include <algorithm>
#include <queue>
using namespace std;
ifstream cin ("lupu.in");
ofstream cout ("lupu.out");
struct sheep_property
{
int dist, wool;
};
priority_queue <int> pq;
sheep_property sheep[100005];
int sheep_nr, wolf_radius, sheep_move, total_wool;
inline bool cmp(sheep_property a, sheep_property b) {
return a.dist < b.dist;
}
void read() {
cin >> sheep_nr >> wolf_radius >> sheep_move;
for(int i = 1; i <= sheep_nr; ++i) {
cin >> sheep[i].dist >> sheep[i].wool;
}
}
void solve() {
sort(&sheep[1], &sheep[sheep_nr] + 1, cmp);
int j = 0;
for(int i = 0; i <= wolf_radius; i += sheep_move) {
for(; sheep[j].dist <= i; ++j) {
pq.push(sheep[j].wool);
}
if(!pq.empty() ) {
total_wool += pq.top();
pq.pop();
}
}
}
void print() {
cout << total_wool << '\n';
}
int main() {
read();
solve();
print();
return 0;
}