#include #include #include "string.h" void func5(void) { int total = 0; int n = 0; int t = 0; int r = 0; int *array = NULL; scanf("%d", &total); scanf("%d", &n); array = malloc(n * sizeof(int)); memset(array, 0, n * sizeof(int)); for (int i = 0; i < n; i++) { scanf("%d", &t); for (int j = 0; j < i; j++) { if (t < array[j]) { int tmp = array[j]; array[j] = t; t = tmp; } } array[i] = t; } for (int i = 0; i < n; ++i) { if (total < array[i]) break; total -= array[i]; r++; } printf("%d\n", r); } int main(void) { func5(); return 0; }