#include #include #include #include using namespace std; int memo[150][10010] = {}; int CalcMaxValue(const vector>& attractions, int index, int t) { if (t == 0) return 0; if (index >= attractions.size()) return 0; if (memo[index][t] == 0) { int cost = attractions[index].first; int value = attractions[index].second; if (t - cost >= 0) { memo[index][t] = max( value + CalcMaxValue(attractions, index + 1, t - cost), CalcMaxValue(attractions, index + 1, t)); } else { memo[index][t] = CalcMaxValue(attractions, index + 1, t); } } return memo[index][t]; } int main() { int t, n; cin >> t >> n; int costs[20]; for (int i = 0; i < n; i++) { cin >> costs[i]; } vector> attractions; for (int i = 0; i < n; i++) { int value; cin >> value; while (value > 0) { attractions.push_back(pair(costs[i], value)); value /= 2; } } cout << CalcMaxValue(attractions, 0, t) << endl; return 0; }