Pagini recente » Cod sursa (job #2125613) | Cod sursa (job #1316875) | Cod sursa (job #2547063) | Cod sursa (job #680336) | Cod sursa (job #440252)
Cod sursa(job #440252)
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
class Gutuie{
public:
unsigned int greutate, nivel;
};
bool comp1(Gutuie a, Gutuie b){
if( a.nivel < b.nivel )
return false;
else
if( a.nivel == b.nivel ){
if( a.greutate > b.greutate )
return true;
else
return false;
}
else
return true;
}
inline unsigned int nivel( unsigned int a, unsigned int u, unsigned int hmax ){
return a % u <= hmax % u ? a / u : 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 nivmax = nivel(hmax, u, hmax);
unsigned int gmax = 0;
priority_queue< unsigned int, vector<unsigned int>, greater<unsigned int> > greutate;
for(i = 0; i < n; i++){
if( greutate.size() < nivmax - v[i].nivel + 1 ){
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;
}