#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define INF 100000000 #define EPS 1e-9 using namespace std; typedef pair P; typedef long long ll; #define MAX_T 10000 #define MAX_N 15 #define MAX_V 500 int T, N; int c[MAX_N]; double v[MAX_N]; int vv[MAX_N * 100000]; int cc[MAX_N * 100000]; int dp[MAX_N+1][MAX_T + 1]; int les(int s, int m){ if (m == 0) return 0; int ans = s / (pow(2, m - 1)) + les(s, m-1); return ans; } int main() { cin >> T; cin >> N; for (int i = 0; i < N; i++){ cin >> c[i]; } for (int i = 0; i < N; i++){ cin >> v[i]; } int count = 0; for (int i = 0; i < N; i++){ while ((int)v[i] > 0){ vv[count] = v[i]; cc[count] = c[i]; count++; v[i] /= 2; } } int ans = 0; for (int i = 0; i < count; i++){ for (int j = 0; j <= T; j++){ if (j - cc[i] < 0) dp[i + 1][j] = dp[i][j]; else dp[i + 1][j] = max(dp[i][j], dp[i][j - cc[i]] + vv[i]); ans = max(ans, dp[i + 1][j]); } } cout << ans << endl; return 0; }