#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int n, m, w; cin >> n >> m >> w; vector a(n), b(n), c(m), d(m); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, m) cin >> c[i]; rep(i, m) cin >> d[i]; ll ans = 0; rep(bit, 1 << (n + m)) { int wei = 0; ll val = 0; rep(i, n) { if (bit & (1 << i)) { wei += a[i]; val += b[i]; } } rep(i, m) { if (bit & (1 << (n + i))) { wei -= c[i]; val -= d[i]; } } if (wei <= w) ans = max(ans, val); } cout << ans << endl; return 0; }