Pagini recente » Borderou de evaluare (job #2853670) | Cod sursa (job #2427007) | Cod sursa (job #309170) | Cod sursa (job #2711513) | Cod sursa (job #433589)
Cod sursa(job #433589)
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <list>
using namespace std;
class gutui_t {
public:
int h;
int g;
float x;
public:
gutui_t(int hval, int gval);
gutui_t(){
h = 0;
g = 0;
x = 0;
}
~gutui_t(){}
};
gutui_t::gutui_t (int hval, int gval){
h = hval;
g = gval;
x = 0;
}
fstream f("gutui.in",ios::in);
fstream out("gutui.out",ios::out);
bool compare (gutui_t fst, gutui_t snd)
{
if ( fst.x > snd.x)
return true;
if (fst.x == snd.x && fst.h > snd.h)
return true;
return false;
}
int main(){
int n, hmax, u, i, size;
list <gutui_t> v;
gutui_t gutuie;
int h, g, val = 0;
f>>n;
f>>hmax;
f>>u;
for (i = 0; i< n; i++){
f>>h>>g;
gutuie.h = h;
gutuie.g = g;
if( h <= hmax){
gutuie.x = (float)gutuie.g / (hmax - gutuie.h);
v.push_back(gutuie);
}
}
i = 0;
while( !v.empty()){
i=0;
v.sort(compare);
gutuie = v.front();
v.pop_front();
val += gutuie.g;
size = v.size();
while( i < size){
gutuie = v.front();
v.pop_front();
gutuie.h += u;
if (gutuie.h <=hmax ){
if(gutuie.h <hmax) gutuie.x = (float)gutuie.g / (hmax - gutuie.h);
if(gutuie.h == hmax) gutuie.x = gutuie.g;
v.push_back(gutuie);
}
i++;
}
}
out<<val;
return 0;
}