#include #include int main(void) { int box_width; int block_all; int count = 0; int i, j, tmp; scanf("%d %d", &box_width, &block_all); int block[block_all]; for(i = 0; i< block_all; i++) scanf("%d", &block[i]); //sort for (i = 0; i < block_all - 1; i++){ for (j = block_all - 1; j > i; j--){ if (block[j - 1] > block[j]){ tmp = block[j]; block[j] = block[j - 1]; block[j - 1]= tmp; } } } int sum = 0; for(count = 0; count < block_all; count++){ sum += block[count]; if(sum > box_width) break; } printf("%d\n", count); return 0; }