#include #include #include #define STR_SIZE 10000 void sortArr(int *arr, int arr_size); void swap(int *x, int *y); int simulation(int size, int *arr, int arr_size); int main(void){ char *str, *token; int box_size, block_num, *block_wid_arr, idx, result; str = (char*)calloc(sizeof(char), STR_SIZE); fgets(str, STR_SIZE, stdin); box_size = atoi(str); fgets(str, STR_SIZE, stdin); block_num = atoi(str); block_wid_arr = (int*)calloc(sizeof(int), block_num); fgets(str, STR_SIZE, stdin); token = strtok(str, " "); for(idx = 0; idx < block_num; idx++) { block_wid_arr[idx] = atoi(token); token = strtok(NULL, " "); } sortArr(block_wid_arr, block_num); /* for(idx = 0; idx < block_num; idx++) { printf("%d ", block_wid_arr[idx]); } */ result = simulation(box_size, block_wid_arr, block_num); printf("%d\n", result); free(str); free(block_wid_arr); return 0; } void sortArr(int *bw_arr, int arr_size) { int i, j; int min; for(i = 0; i < arr_size; i++) { min = 10001; for(j = i; j < arr_size; j++) { if(bw_arr[j] < min) { min = bw_arr[j]; swap(&bw_arr[i], &bw_arr[j]); } } } } void swap(int *x, int *y) { int tmp; tmp = *x; *x = *y; *y = tmp; } int simulation(int bs, int *bl_arr, int bls) { int i, ret = 0; for(i = 0; i < bls; i++) { bs -= bl_arr[i]; if(bs < 0) { break; } ret++; } return ret; }