#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include "bits/stdc++.h" using namespace std; // #include // using namespace atcoder; // using mint = modint998244353; using Graph = vector>; #define all(v) v.begin(), v.end() #define inf 2147483647 #define INF 9223372036854775807 #define gcd(a, b) __gcd((a), (b)) #define ll long long #define fi first #define se second #define mod107 1000000007 #define mod998 998244353; #define eps 1e-9 #define PI acos(-1) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define SHOW(x) std::clog << #x ": " << (x) << std::endl template using max_heap = priority_queue; template using min_heap = priority_queue, greater<>>; template istream &operator>>(istream &s, vector &v) { for (auto &e : v) s >> e; return s; } template ostream &operator<<(ostream &s, const vector &v) { for (auto &e : v) s << e << ' '; return s; } template ostream &operator<<(ostream &s, const pair &p) { s << p.first << ' ' << p.second; return s; } int dx[8] = {-1, 0, 1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; struct edge { ll to, cost; }; ll lcm(ll a, ll b) { // オーバーフローしない return a / __gcd(a, b) * b; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int N,M,W; cin >> N >> M >> W; vector A(N); vector B(N); vector C(M); vector D(M); vector E(N + M); vector F(N + M); cin >> A; cin >> B; cin >> C; cin >> D; for(int i = 0;i < N;i++){ E[i] = A[i]; } for(int i = 0;i < N;i++){ F[i] = B[i]; } for(int i = 0;i < M;i++){ E[i + N] = C[i]; } for(int i = 0;i < M;i++){ F[i + N] = D[i]; } ll ans = 0; ll nm = N + M; for(int bit = 0;bit < (1 << nm);bit++){ ll w = 0; ll pre = 0; for(int i = 0;i < nm;i++){ if(bit & (1 << i)){ if(i < N){ w += E[i]; pre += F[i]; } else{ w -= E[i]; pre -= F[i]; } } } if(w <= W){ ans = max(ans,pre); } } cout << ans << endl; }