Pagini recente » Cod sursa (job #1203215) | Cod sursa (job #1209469) | Cod sursa (job #1139003) | Cod sursa (job #602737) | Cod sursa (job #441670)
Cod sursa(job #441670)
#include <stdlib.h>
#include <stdio.h>
#define file_in "gutui.in"
#define file_out "gutui.out"
typedef struct fruit_
{
long int height;
long int weight;
} fruit;
int comp(const void *o1, const void *o2)
{
fruit *a = (fruit *)o1;
fruit *b = (fruit *)o2;
if((*a).height != (*b).height)
return (*b).height - (*a).height;
else
return (*b).weight - (*a).weight;
}
int main()
{
fruit *fruits;
long int i, j, max, N, H, U, *best;
freopen(file_in, "rt", stdin);
freopen(file_out, "wt", stdout);
scanf("%li %li %li", &N, &H, &U);
fruits = (fruit *)malloc(N*sizeof(fruit));
best = (long int *)malloc(N*sizeof(long int));
for(i = 0; i < N; i++)
scanf("%li %li", &fruits[i].height, &fruits[i].weight);
qsort(fruits, N, sizeof(fruit), comp);
for(i=0;i<N;i++)
{
max = 0;
for(j=0;j<i;j++)
{
if((fruits[j].height >= fruits[i].height)&&(fruits[j].height+(j*U) <= H)&&(max < best[j]))
max = best[j];
}
best[i] = max + fruits[i].weight;
}
max = 0;
for(i=0;i<N;i++)
if(max < best[i])
max = best[i];
/*j = 0;
sum = 0;
for(i=0;i<N;i++)
{
if(fruits[i].height + (j * U) <= H)
{
sum += fruits[i].weight;
j++;
}
}*/
printf("%li\n", max);
free(fruits);
free(best);
fclose(stdin);
fclose(stdout);
return 0;
}