Cod sursa(job #442248)

Utilizator sshdas21Ionut Moise sshdas21 Data 13 aprilie 2010 23:54:29
Problema Gutui Scor 10
Compilator cpp Status done
Runda teme_upb Marime 0.95 kb
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define file_in "gutui.in"
#define file_out "gutui.out"

typedef struct fruit_
{
	long int height;
	long int weight;
} fruit;


int main()
{
	
	fruit *fruits;
	long int i, j, max, N, U, H, *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);

	for(i=0;i<N;i++)
		best[i] = 0;
	
	for(i=0;i<N;i++)
	{
		max = 0;
		for(j=0;j<i;j++)
			if((i != j) && (fruits[j].height + 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];
	}

	printf("%li", max);

	free(fruits);
	free(best);
	fclose(stdin);
	fclose(stdout);

	return 0;
}