Pagini recente » Cod sursa (job #238845) | Cod sursa (job #2382720) | Cod sursa (job #236353) | Cod sursa (job #1118618) | Cod sursa (job #434727)
Cod sursa(job #434727)
/*
* =====================================================================================
*
* 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;
}