#include #include using namespace std; int main() { int N, M, W; cin >> N >> M >> W; int n = N + M; int wei[20]; int val[20]; for (int i = 0; i < N; i++) { cin >> wei[i]; } for (int i = 0; i < N; i ++) { cin >> val[i]; } for (int i = N; i < N + M; i++) { cin >> wei[i]; wei[i] *= -1; } for (int i = N; i < N + M; i++) { cin >> val[i]; val[i] *= -1; } int inf = 1e9 + 7; vector> dp(1 << n, vector(W + 1, -inf)); dp[0][0] = 0; for (int i = 1; i < (1 << n); i++) { for (int j = 0; j < n; j++) { if ((i >> j) & 1) { for (int k = 0; k <= W; k++) { dp[i][k] = max(dp[i][k], dp[i - (1 << j)][k]); } for (int k = max(0, -wei[j]); k <= min(W, W - wei[j]); k++) { dp[i][k + wei[j]] = max(dp[i][k + wei[j]], dp[i - (1 << j)][k] + val[j]); } } } } int ans = 0; for (int i = 0; i <= W; i++) { ans = max(ans, dp[(1 << n) - 1][i]); } cout << ans << endl; }