#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); ll N,M,W; cin >> N >> M >> W; vector A(N); vector B(N); vector C(M); vector D(M); cin >> A; cin >> B; cin >> C; cin >> D; ll ans = 0; ll nm = N + M; vector s(1 << nm,0); for(int i = 0;i < (1 << nm);i++){ for(int j = 0;j < N;j++){ if((i >> j) & 1 == 1){ s[i] += A[j]; } } for(int j = 0;j < M;j++){ if((i >> (N + j) & 1) == 1){ s[i] -= C[j]; } } } vector dp(1 << nm,-inf); dp[0] = 0; // for (int i = 0; i < (1 << (N + M)); i++){ // if (0 <= s[i] && s[i] <= W){ // for (int j = 0; j < N + M; j++){ // if ((i >> j & 1) == 0){ // int i2 = i | (1 << j); // if (0 <= s[i2] && s[i2] <= W){ // if (j < N){ // dp[i2] = max(dp[i2], dp[i] + B[j]); // } else { // dp[i2] = max(dp[i2], dp[i] - D[j - N]); // } // } // } // } // } // } for(int i = 0;i < (1 << nm);i++){ if(0 <= s[i] && s[i] <= W){ for(int j = 0;j < nm;j++){ if((i >> j & 1) == 0){ int i2 = i | (1 << j); if(0 <= s[i2] && s[i2] <= W){ if(j < N){ dp[i2] = max(dp[i2],dp[i] + B[j]); } else{ dp[i2] = max(dp[i2],dp[i] - D[j - N]); } } } } } } for(int i = 0;i < (1 << nm);i++){ ans = max(ans,dp[i]); } cout << ans << endl; }