#include #include using namespace std; int main() { int max; int n; cin >> max; cin >> n; multiset blocks; for ( auto i = 0; i < n; i++ ) { int x; cin >> x; blocks.insert(x); } // maxを超えないブロック数を小さい順から数えればOKなはず int count = 0; int t = 0; for ( auto block : blocks ) { if ( t + block > max ) { break; } count++; t += block; } cout << count << endl; }