Pagini recente » Cod sursa (job #1664806) | Cod sursa (job #3166274) | Cod sursa (job #2068724) | Cod sursa (job #2906741) | Cod sursa (job #1123017)
#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;
Oaie(){}
Oaie(int a ,int b){
d=a;
l=b;
}
};
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]=Oaie(a,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;
}