#include #include using namespace std; const int kMAX_N = 16; const int kMAX_T = 10010; int N, T; int c[kMAX_N], v[kMAX_N]; int max_value[kMAX_N][kMAX_T]; void Solve() { memset(max_value, -1, sizeof(max_value)); max_value[0][0] = 0; for (int i = 0; i < N; i++) { for (int ti = 0; ti <= T; ti++) { if (max_value[i][ti] < 0) continue; int val = 0, next = v[i], times = 0; while (ti + c[i] * times <= T) { max_value[i + 1][ti + c[i] * times] = max(max_value[i + 1][ti + c[i] * times], max_value[i][ti] + val); if (next == 0) break; val += next; times++; next /= 2; } } } int answer = 0; for (int ti = 0; ti <= T; ti++) answer = max(answer, max_value[N][ti]); cout << answer << endl; } int main() { cin >> T >> N; for (int i = 0; i < N; i++) { cin >> c[i]; } for (int i = 0; i < N; i++) { cin >> v[i]; } Solve(); return 0; }