Pagini recente » Cod sursa (job #502690) | Cod sursa (job #2044914) | Cod sursa (job #520149) | Cod sursa (job #472807) | Cod sursa (job #432990)
Cod sursa(job #432990)
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
typedef struct gs{
int hg;
int gg;
//int ig;
} gs;
int n,h,u;
gs *gt;
int * luate;
int nr_luate = 0;
int p;
int gmax = 0;
int nivmax = 0;
int nivmin = 100000;
int compare (const void * a, const void * b)
{
return ( ((gs *)b)->gg - ((gs *)a)->gg);
}
int get_gmax(){
//cout<<"nivmax = "<<nivmax<<", nivmin = "<<nivmin<<", p = "<<p<<endl;
int i,j;
int k;
for(i=0;i<p;i++){
k = 0;
for(j=0;j<nr_luate;j++){ /* cate s-au luat de "mai sus" */
if(luate[j] >= gt[i].hg){
k++;
}
}
if(nivmax + 1 - gt[i].hg - k > 0 ){
luate[nr_luate++] = gt[i].hg;
gmax = gmax + gt[i].gg;
}
else{
p++;
}
}
return 0;
}
int read_vec(){
ifstream fin;
int i;
fin.open("gutui.in",ios::in);
fin>>n;
fin>>h;
fin>>u;
gt = (gs *)malloc( n * sizeof( gs ));
nivmax = h/u + ((h%u == 0)?0:1);
for(i=0;i<n;i++){
fin>>gt[i].hg;
fin>>gt[i].gg;
gt[i].hg = (gt[i].hg / u) + ( (gt[i].hg % u == 0) ? 0 : 1 ) ;
if(gt[i].hg < nivmin){
nivmin = gt[i].hg;
}
}
p = nivmax - nivmin + 1;
if(p > n){
p = n;
}
luate = (int *)malloc( p * sizeof( int ));
qsort (gt, n, sizeof(gs), compare);
fin.close();
return 0;
}
int write_sol(){
ofstream fout;
fout.open("gutui.out",ios::out);
fout<<gmax;
fout.close();
return 0;
}
int main(){
read_vec();
get_gmax();
write_sol();
//cout<<"gmax ="<< gmax;
//cin.get();//to_comment
return 0;
}