Pagini recente » Cod sursa (job #297238) | Cod sursa (job #461581) | Cod sursa (job #70417) | Cod sursa (job #17404) | Cod sursa (job #440634)
Cod sursa(job #440634)
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
class Gutuie{
public:
unsigned int greutate, nivel;
};
bool comp1(Gutuie &a, Gutuie &b){
return a.nivel < b.nivel;
}
inline unsigned int nivel( unsigned int &a, unsigned int &u, unsigned int &hmax ){
return (hmax - a) / u + 1;
}
int main(){
unsigned int n, u, hmax;
ifstream fin("gutui.in");
ofstream fout("gutui.out");
fin >> n >> hmax >> u;
unsigned int i, x;
vector<Gutuie> v(n);
for(i = 0; i < n; i++){
fin >> x >> v[i].greutate;
v[i].nivel = nivel(x, u, hmax);
}
sort( v.begin(), v.end(), comp1 );
unsigned int gmax = 0;
priority_queue< unsigned int, vector<unsigned int>, greater<unsigned int> > greutate;
for(i = 0; i < n; i++){
if( greutate.size() < v[i].nivel ){
gmax += v[i].greutate;
greutate.push( v[i].greutate );
}
else
if( greutate.top() < v[i].greutate ){
gmax -= greutate.top();
gmax += v[i].greutate;
greutate.pop();
greutate.push( v[i].greutate );
}
}
fout << gmax;
fin.close();
fout.close();
return 0;
}