#include #include using namespace std; #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) int main(void) { int l, n, c = 0, t = 0; cin >> l; cin >> n; int w[n]; for (int i = 0; i < n; i++) std::cin >> w[i]; sort(w, w + SIZE_OF_ARRAY(w)); for (int i = 0; i < n; i++) { t += w[i]; c++; if (t > l) { c--; break; } } cout << c << endl; }