天天看点

URAL 1279 Warehouse

#include <stdio.h>
#define MAX_HIGHT 1000

int numOfRows, numOfColumns, numOfNewContainers;
int sections[MAX_HIGHT + 1];
int result;

int main(){
	
	scanf("%d%d%d", &numOfRows, &numOfColumns, &numOfNewContainers);
	int row, column, initailHight;
	for (row = 1; row <= numOfRows; row++){
		for (column = 1; column <= numOfColumns; column++){
			scanf("%d", &initailHight);
			sections[initailHight]++;
		}
	}

	int preNewContainersPlaced = 0;
	int hight, newContainersPlaced;
	for (hight = 1; hight <= MAX_HIGHT; hight++){
		//往原来高度为hight的section都放上一个container
		newContainersPlaced = preNewContainersPlaced + sections[hight];
		if (newContainersPlaced < numOfNewContainers){
			preNewContainersPlaced = newContainersPlaced;
			sections[hight + 1] += sections[hight];
		} else if (newContainersPlaced == numOfNewContainers){
			result = hight + 1;
			break;
		} else {
			result = hight;
			break;
		}
	}

	printf("%d\n", result);
	
	return 0;
}