Pagini recente » Cod sursa (job #1651308) | Cod sursa (job #59850) | Cod sursa (job #621581) | Cod sursa (job #1442125) | Cod sursa (job #1127384)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <queue>
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
const int N=1+1e6;
struct Oaie{
int d,l;
};
priority_queue<int> h;
Oaie o[N];
int n,x,f,k;
bool cmp(Oaie a, Oaie b){
return a.d>b.d;
}
int main()
{
int a,b;
in>>n>>x>>f;
for(int i=1 ; i<=n ; i++){
in>>a>>b;
if(a<=x){
o[++k].d=a;
o[k].l=b;
}
}
sort(&o[1], &o[k+1], cmp);
for(int i=1 ; i<=k ; i++){
if( o[i].d + (h.size())*f <=x){
h.push(-o[i].l);
}else{
if(-o[i].l<h.top()){
h.pop();
h.push(-o[i].l);
}
}
}
int s=0;
while(!h.empty()){
s+=h.top();
h.pop();
}
out<<-s;
return 0;
}