#include #include int cmp(const void* n1, const void* n2) { if (*(long*)n1 > *(long*)n2) { return 1; } else if (*(long*)n1 < *(long*)n2) { return -1; } else { return 0; } } int main() { int l, n, w[100]; scanf("%d", &l); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &w[i]); } qsort(w, n, sizeof(int), cmp); int i = 0, j = 0; while (i < n) { j += w[i]; if (l < j) { break; } i++; } printf("%d", i); return 0; }