/* * 733_sample.cpp * * No.733 分身並列コーディング */ #include #include using V = std::vector; int pattern(const V& times, const int& time, const int& num, const int& first) { auto times2 = times; if (first != 0) { times2[0] = times[first]; times2[first] = times[0]; } for (auto i = 0; i < num-1; i++) { if (times2[i] > 0) { for (auto j = i+1; j < num; j++) { if (times2[j] > 0) { auto tmp = times2[i] + times2[j]; if (time >= tmp) { times2[i] = tmp; times2[j] = -1; } } } } } auto count = 0; for (auto i = 0; i < num; i++) { if (times2[i] > 0) { count++; } } return count; } int main () { auto time = 0; auto num = 0; std::cin >> time >> num; V times(num); for (auto i = 0; i < num; i++) { std::cin >> times[i]; } auto ans = num; for (auto i = 0; i < num; i++) { auto count = pattern(times, time, num, i); if (ans > count) { ans = count; } } std::cout << ans << std::endl; return 0; }