#include using namespace std; int main() { int N, T, C[20], V[20]; cin >> T >> N; for (int i = 0; i < N; i++) { cin >> C[i]; } for (int i = 0; i < N; i++) { cin >> V[i]; } int dp[10010] = {}; for (int i = 0; i < N; i++) { for (int t = T; t >= 0; t--) { int c = C[i], v = V[i], sum = 0; for (int times = 1; times < 10; times++) { int nxt_t = t + times * c; sum += v; if (nxt_t <= T) { dp[nxt_t] = max(dp[nxt_t], dp[t] + sum); } v >>= 1; } } } cout << dp[T] << endl; }