Skip to content

Theme Park

My solution for the Problem C "Theme Park" of Google Code Jam 2010 qualification round (in C language):


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int T, t;
int R, k, N;
int r, n, g, peoples, groups;

int Group[1000];
long long Euro;

main() {
	long long *Income;

	Income = (long long *)malloc(100000000 * sizeof(long long));
	if (Income == NULL) {
		printf(" -- alloc failed\n");
		exit(1);
	}

  fscanf(stdin, "%d", &T);

  for (t = 0; t < T; t++) {
	fscanf(stdin, "%d %d %d", &R, &k, &N);
	for (n = 0; n < N; n++) {
		fscanf(stdin, "%d", &Group[n]);
	}

	g = 0;
	Euro = 0;
	for (r = 0; r < R; ) {
		for(peoples = groups = 0; (peoples + Group[g] <= k) && (groups < N); groups++ ) {
			Euro += Group[g];
			peoples += Group[g];
			g = (g + 1) % N;
		}
		Income[r] = Euro;
		r++;
		if (g == 0) {
			Euro = Euro * (R / r);
			if ((R % r) > 0) Euro += Income[(R % r) - 1];
			break;
		}
	}
    printf("Case #%d: %lld\n", t + 1, Euro);
  }

	free(Income);

  return 0;
}

3 thoughts on “Theme Park

  1. Pingback: Tweets that mention Theme Park | Founds -- Topsy.com

  2. Pingback: update Twitter ด้วย twitter.lib.php аё—аёіаё‡аёІаё™аёљаё™ Shell « NAzT's Blog

  3. jana

    Thanks a lot for helping me out. Your weblog solved my problem of “Theme Park” that was pinching me day and night.

Leave a Reply

Your email address will not be published. Required fields are marked *