View Code of Problem 33

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

#define N 1000

int main()
{
	int M, T, n, i, j, k = 0, sum = 0, l, special_num[N], hp[N] = {0}, num[N];
	int rest = 0, get = 0, ssum = 0;

	scanf("%d", &T);

	for(i = 0; i < T; i++){
		scanf("%d", &M);

		for(j = 0; j < M; j++){
			scanf("%d", &special_num[j]);
			ssum += special_num[j];

			for(; k < special_num[j] + ssum; k++){
				scanf("%d", &hp[k]);
			}
		}

		for(j = 0; j < M; j++){
			scanf("%d", &num[j]);
		}

		for(j = 0; j < M; j++){
			sum = num[j] + rest;

			for(k = 0; k < ssum - 1; k++){
				int count = k;
				
				for(l = k + 1; l < ssum; l++){
					if(hp[count] > hp[l]){
						count = l;
					}

					if(count != k){
						int temp = hp[count];
						hp[count] = hp[k];
						hp[k] = temp;
					}
				}
			}
			for(k = 0; k < ssum; k++){
				if(sum >= hp[k]){
					sum -= hp[k];
					get++;
				}
				else 
				{
					rest = sum;
					break;
				}
			}
		}
		printf("%d\n", get);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 33