#include #include #include #include #include #include #include #include #include #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define MAX 15 #define NUM 10000 typedef long long ll; using namespace std; int inputValue(){ int a; cin >> a; return a; }; void inputArray(int * p, int a){ rep(i, a){ cin >> p[i]; } }; void inputVector(vector * p, int a){ rep(i, a){ int input; cin >> input; p -> push_back(input); } } template void output(T a, int precision) { if(precision > 0){ cout << setprecision(precision) << a << "\n"; } else{ cout << a << "\n"; } } int main(int argc, const char * argv[]) { // source code int T = inputValue(); int N = inputValue(); int c[MAX] = {0}; int v[MAX] = {0}; int dp[NUM]; rep(i, N){ c[i] = inputValue(); } rep(i, N){ v[i] = inputValue(); } rep(i, N){ while (v[i] != 0) { for (int j = T; j >= 0; j--) { if (j >= c[i]) { dp[j] = max(dp[j], dp[j - c[i]] + v[i]); } } v[i] /= 2; } } int ret = 0; rep(i, T + 1){ ret = max(ret, dp[i]); } output(ret, 0); return 0; }