#include using namespace std; template bool is_kth_bit_set(T n, int k) { return n >> k & 1; } #define rep(i, n) for (int i = 0; i < n; i++) template std::istream &operator>>(std::istream &is, std::vector &a) { int n = a.size(); rep(i, n) { is >> a[i]; } return is; } template void chmax(T &a, T b) { if (b > a) a = b; } template vector products(F &f, vector &a) { int n = a.size(); vector b(1 << n); rep(i, n) rep(s, 1 << i) { b[s | 1 << i] = f(b[s], a[i]); } return b; } auto main() -> int { int n, m, w; cin >> n >> m >> w; vector a(n), b(n), c(m), d(m); cin >> a >> b >> c >> d; int l = n + m; int l2 = 1 << l; vector dw(l), dv(l); rep(i, l) { dw[i] = i < n ? a[i] : -c[i - n]; dv[i] = i < n ? b[i] : -d[i - n]; } auto op = [](long x, int y) { return x + y; }; vector v = products(op, dv); vector wt = products(op, dw); vector ok(l2); ok[0] = true; long mx = 0; rep(s, l2) { if (!ok[s]) continue; chmax(mx, v[s]); rep(i, l) { if (s >> i & 1) continue; int u = s | 1 << i; if (0 <= wt[u] && wt[u] <= w) ok[u] = true; } } cout << mx << endl; }