Pagini recente » Cod sursa (job #259071) | Cod sursa (job #1271067) | Cod sursa (job #2090377) | Cod sursa (job #1686345) | Cod sursa (job #3141609)
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
ifstream cin("lupu.in");
ofstream cout("lupu.out");
struct oaie{
int dist;
int blana;
bool operator <(const oaie &other)const{
return dist < other.dist;
}
};
vector <oaie> oi;
priority_queue <int> pq;
int main() {
int n, x, l;
long long sum = 0;
cin >> n >> x >> l;
for(int i = 0; i < n; i++){
oaie coaie;
cin >> coaie.dist >> coaie.blana;
if(coaie.dist <= x)
oi.push_back(coaie);
}
sort(oi.begin(), oi.end());
int nivel = x/ l + 1;
for(int i = 0; i < oi.size(); i++) {
int candidateNivel = (x - oi[i].dist) / l + 1;
if (candidateNivel < nivel) {
for(int j = 0; j < nivel - candidateNivel && !pq.empty(); j++) {
sum += pq.top();
pq.pop();
}
nivel = (x - oi[i].dist) / l + 1;
}
pq.push(oi[i].blana);
}
while(nivel && !pq.empty()) {
sum += pq.top();
pq.pop();
nivel--;
}
// pq.pop();
cout << sum;
return 0;
}