#include #include static 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; scanf("%d", &l); scanf("%d", &n); int* w; w = (int*)malloc(sizeof(int) * n); if (w) { for (int i = 0; i < n; i++) { scanf("%d", &w[i]); } if (sizeof(w) != sizeof(long)){ printf("ERROR"); return 0; } 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); } free(w); return 0; }