//================================= // Created on: 2018/09/07 21:49:21 //================================= #include #define show(x) std::cerr << #x << " = " << x << std::endl using ll = long long; using ull = unsigned long long; using ld = long double; constexpr ll MOD = 1000000007LL; template constexpr T INF = std::numeric_limits::max() / 10; std::mt19937 mt{std::random_device{}()}; int main() { int T, N; std::cin >> T >> N; std::vector t(N); for (int i = 0; i < N; i++) { std::cin >> t[i]; } std::sort(t.begin(), t.end(), std::greater{}); auto check = [&](const int n) { std::priority_queue, std::greater> q; for (int i = 0; i < n; i++) { q.push(0); } for (int i = 0; i < N; i++) { const int p = q.top(); q.pop(); q.push(p + t[i]); } while (not q.empty()) { if (q.top() > T) { return false; } q.pop(); } return true; }; int inf = 0, sup = N + 1; while (sup - inf > 1) { const int mid = (inf + sup) / 2; (check(mid) ? sup : inf) = mid; } std::cout << sup << std::endl; return 0; }