#include using namespace std; auto main() -> int { int n, m, W; cin >> n >> m >> W; vector a(n), b(n), c(m), d(m); 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]; } int l = n + m; int l2 = 1 << l; const long inf = 1l << 60; vector> dp(l2, vector(W + 1, -inf)); dp[0][0] = 0; for (int s = 0; s < l2; s++) { for (int i = 0; i < l; i++) { if (s >> i & 1) continue; int u = s | 1 << i; for (int j = 0; j <= W; j++) { dp[u][j] = max(dp[u][j], dp[s][j]); } if (i < n) { int dw = a[i]; int dv = b[i]; for (int j = W; j >= dw; j--) { dp[u][j] = max(dp[u][j], dp[s][j - dw] + dv); } } else { int dw = c[i - n]; int dv = d[i - n]; for (int j = 0; j <= W - dw; j++) { dp[u][j] = max(dp[u][j], dp[s][j + dw] - dv); } } } } cout << *max_element(dp[l2 - 1].begin(), dp[l2 - 1].end()) << endl; }