#include int main(void) { int width, number, tmp, count; count = 0; scanf("%d", &width); scanf("%d", &number); int haba[number]; for (int x = 0; x < number; x++) { scanf("%d", &haba[x]); } //数値を昇順にソート for (int i = 0; i < number; ++i) { for (int j = i + 1; j < number; ++j) { if (haba[i] > haba[j]) { tmp = haba[i]; haba[i] = haba[j]; haba[j] = tmp; } } } for (int y = 0; y < number; y++) { if (width >= 0) { width = width - haba[y]; if (width <= 0) { break; } else { count++; } } else { break; } } printf("%d", count); }