#include #include using namespace std; int dp[100001]; int memo[100001][15]; int c[15]; int v[15]; int main(void){ int T; int N; cin >> T >> N; for (int i = 0; i < N; i++){ cin >> c[i]; } for (int i = 0; i < N; i++){ cin >> v[i]; memo[0][i] = v[i]; } for (int i = 0; i < T; i++){ for (int j = 0; j < N; j++){ if (i + c[j] <= T&&dp[i + c[j]] < dp[i] + memo[i][j]){ dp[i + c[j]] = dp[i] + memo[i][j]; for (int k = 0; k < N; k++){ memo[i + c[j]][k] = memo[i][k]; } memo[i + c[j]][j] /= 2; } } } int res = 0; for (int i = 0; i <= T; i++){ res = max(dp[i], res); } cout << res << endl; }