#include #include #include #include using namespace std; #define loop(i,a,b) for(int i=(a);i> T >> N; rep(i, N)cin >> c[i]; rep(i, N)cin >> v[i]; vector v_; vector w_; rep(i, N){ rep(j, 10){ if (v[i] >> j){ v_.push_back(v[i] >> j); w_.push_back(c[i]); } else { break; } } } rep(i, v_.size()){ for (int j = T; j >= 0; j--){ if (j - w_[i] >= 0)dp[j] = max(dp[j - w_[i]] + v_[i], dp[j]); } } cout << dp[T] << endl; }