#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; int N, M, W, A[10], B[10], C[10], D[10]; ll dp[1 << 7][1 << 7][501]; int main() { cin >> N >> M >> W; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; for (int i = 0; i < M; i++) cin >> C[i]; for (int i = 0; i < M; i++) cin >> D[i]; for (int i = 0; i < (1 << N); i++) { for (int j = 0; j < (1 << M); j++) { for (int k = 0; k <= W; k++) { dp[i][j][k] = -1e18; } } } dp[0][0][0] = 0; ll ans = -1e18; for (int i = 0; i < (1 << N); i++) { for (int j = 0; j < (1 << M); j++) { for (int k = 0; k <= W; k++) { ans = max(ans, dp[i][j][k]); for (int l = 0; l < N; l++) { if (i >> l & 1) continue; int ni = i | (1 << l); int nxt = k + A[l]; if (nxt > W) continue; dp[ni][j][nxt] = max(dp[ni][j][nxt], dp[i][j][k] + B[l]); } for (int l = 0; l < M; l++) { if (j >> l & 1) continue; int nj = j | (1 << l); int nxt = k - C[l]; if (nxt < 0) continue; dp[i][nj][nxt] = max(dp[i][nj][nxt], dp[i][j][k] - D[l]); } } } } cout << ans << endl; return 0; }