Cod sursa(job #434727)

Utilizator carbonixVictor Carbune carbonix Data 6 aprilie 2010 14:35:53
Problema Gutui Scor 0
Compilator c Status done
Runda teme_upb Marime 1.22 kb
/*
 * =====================================================================================
 *
 *       Filename:  gutui.c
 *
 *    Description:  Problem solution description here
 *
 *         Author:  Victor Carbune ([email protected])
 *	     Info:  Grupa 325, Seria CA
 *
 * =====================================================================================
 */

#include <stdio.h>

struct {
	int h, w;
} gutui [1000];

int n, hmax, u;

void read() {
	int i, flag = 0;
	
	scanf("%d %d %d", &n, &hmax, &u);
	for ( i = 0; i < n; i++ ) 
		scanf("%d %d", &gutui[i].h, &gutui[i].w);
}

void sort_gutui() {
	int i, flag = 0; 
	
	while(!flag) {
		flag = 1;

		for ( i = 0; i < n - 1; i++ )
			if( (hmax - gutui[i].h) > (hmax - gutui[i+1].h) ) {
				gutui[i].w ^= gutui[i+1].w;
				gutui[i+1].w ^= gutui[i].w;
				gutui[i].w ^= gutui[i+1].w;

				gutui[i].h ^= gutui[i+1].h;
				gutui[i+1].h ^= gutui[i].h;
				gutui[i].h ^= gutui[i+1].h;

				flag = 0;
			}
	}
}

int main() {
	int i, gmax = 0, currentTreeHeight = 0;
	freopen("in", "r", stdin);
	read();
	sort_gutui();

	for ( i = 0; i < n; i++ ) {
		if (gutui[i].h + currentTreeHeight <= hmax) {
			gmax += gutui[i].w;
			currentTreeHeight += u;
		}
	}
	printf("%d\n", gmax);

	return 0;
}