Friday, April 24, 2015

UVa 11968 - In The Airport

// UVa 11968 - In The Airport

#include <stdio.h>
#include <math.h>

int main() {
	int cases;
	scanf("%d", &cases);
	for (int cas = 1; cas <= cases; cas++) {
		int n, m, k;
		long long cakes[1000], drinks[1000];
		long long total = 0;
		scanf("%d %d %d", &n, &m, &k);
		for (int i = 0; i < m; i++) {
			scanf("%d", &cakes[i]);
			total += cakes[i];
		}
		for (int i = 0; i < k; i++) {
			scanf("%d", &drinks[i]);
			total += drinks[i];
		}
		for (int i = 0; i < n - m - k; i++) {
			long long price;
			scanf("%d", &price);
			total += price;
		}
		double avg = total / double(n);

		int best_cake = cakes[0];
		double best_distance = fabs(cakes[0] - avg);
		for (int i = 1; i < m; i++) {
			double this_distance = fabs(cakes[i] - avg);
			if (this_distance < best_distance || (this_distance == best_distance && cakes[i] < best_cake)) {
				best_distance = this_distance;
				best_cake = cakes[i];
			}
		}
		int best_drink = drinks[0];
		best_distance = fabs(drinks[0] - avg);
		for (int i = 1; i < k; i++) {
			double this_distance = fabs(drinks[i] - avg);
			if (this_distance < best_distance || (this_distance == best_distance && drinks[i] < best_drink)) {
				best_distance = this_distance;
				best_drink = drinks[i];
			}
		}

		printf("Case #%d: %d %d\n", cas, best_cake, best_drink);
	}
	return 0;
}

No comments:

Post a Comment