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