#line 1 "template/template.hpp" #include using ll = long long; #define REP(i, n) for(ll i = 0; (i) < ll(n); ++ (i)) #define FOR(i, m, n) for(ll i = (m); (i) <= ll(n); ++ (i)) #define REPR(i, n) for(ll i = ll(n) - 1; (i) >= 0; -- (i)) #define FORR(i, m, n) for(ll i = ll(n); (i) >= ll(m); -- (i)) #define ALL(x) x.begin(),x.end() #define INF (int)1e9 #define LLINF (long long)1e18 #define MOD (int)(1e9+7) #define MOD9 (int)998244353 #define PI 3.141592653589 #define PB push_back #define F first #define S second #define YESNO(T) if(T){cout<<"YES"< > #define CostGraph vector > > #define PII pair #define PLL pair #define VI vector #define VL vector #define VVI vector > #define VVL vector > #define VPII vector > #define VPLL vector > #define DDD fixed< inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false; } template inline bool chmax(T &a, T b) { if(a < b){a = b; return true;} return false; } struct input{ int n; input() {} input(int n_) : n(n_){}; template operator T(){ T ret; std::cin >> ret; return ret; } template operator std::vector() { std::vector ret(n); REP(i,n) std::cin >> ret[i]; return ret; } }; template inline void printVec(std::vector v){ REP(i,v.size()){ if(i) std::cout << " "; std::cout << v[i]; } std::cout << std::endl; } using namespace std; #line 2 "data-structure/unionfind.hpp" struct UnionFind { vector parent; vector rank; UnionFind(int n) { init(n); } void init(int n) { parent.resize(n); rank.resize(n); for(int i = 0; i < n; ++i){ parent[i] = i; rank[i] = 0; } } int getRoot(int x) { if(parent[x] == x) return x; return parent[x] = getRoot(parent[x]); } bool isSame(int x, int y) { return getRoot(x) == getRoot(y); } bool merge(int x, int y) { x = getRoot(x); y = getRoot(y); if(x == y) return false; if(rank[x] < rank[y]) swap(x, y); if(rank[x] == rank[y]) ++rank[x]; parent[y] = x; return true; } vector> getGroups(){ int n = rank.size(); vector> rest(n), res; for(int i = 0; i < n; ++i) rest[getRoot(i)].push_back(i); for(int i = 0; i < n; ++i) if(rest[i].size()) res.push_back(rest[i]); return res; } }; #line 3 "main.cpp" int main(){ int n, m, w; cin >> n >> m >> w; VI a = input(n); VI b = input(n); VI c = input(m); VI d = input(m); VI t(n+m); iota(ALL(t), 0); int ans = 0; do{ int val = 0; int wgt = 0; REP(i,n+m){ if(t[i] < n){ if(wgt + a[t[i]] <= w){ wgt += a[t[i]]; val += b[t[i]]; } }else{ if(wgt - c[t[i] - n] >= 0){ wgt -= c[t[i] - n]; val -= d[t[i] - n]; } } chmax(ans, val); } }while(next_permutation(ALL(t))); cout << ans << endl; }