#include #include using std::vector; int optimal_weight(int W, const vector &w) { //write your code here int current_weight = 0; for (size_t i = 0; i < w.size(); ++i) { if (current_weight + w[i] <= W) { current_weight += w[i]; } } return current_weight; } int main() { int n, W; std::cin >> W >> n; vector w(n); for (int i = 0; i < n; i++) { std::cin >> w[i]; } std::cout << optimal_weight(W, w) << '\n'; }