#include #include int compare_int(const void *a, const void *b) { return *(int*)a - *(int*)b; } int main() { int i,l,n,w[10010] = {0},sum = 0,ans = 0; scanf("%d",&l); scanf("%d",&n); for (i = 0; i < n; i++) { scanf("%d",&w[i]); } qsort(w, n, sizeof(int), compare_int); while(ans < n){ sum += w[ans]; if(sum > l) break; ans++; } printf("%d",ans); return 0; }