#include #include #include using namespace std; using lint = long long; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; } int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); } template IStream &operator>>(IStream &is, std::vector &vec) { for (auto &v : vec) is >> v; return is; } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N, M, W; cin >> N >> M >> W; vector A(N), B(N), C(M), D(M); cin >> A >> B >> C >> D; constexpr lint inf = 1LL << 60; vector dp(1 << (N + M), -inf); vector weight(1 << (N + M), 0); dp.front() = 0; FOR(S, 1, 1 << (N + M)) { int i = floor_lg(S); weight.at(S) = weight.at(S - (1 << i)) + (i < N ? A.at(i) : -C.at(i - N)); } REP(S, 1 << (N + M)) { REP(i, N + M) { if ((S >> i) & 1) continue; if (weight.at(S | (1 << i)) > W) continue; if (weight.at(S | (1 << i)) < 0) continue; chmax(dp.at(S | (1 << i)), dp.at(S) + (i < N ? B.at(i) : -D.at(i - N))); } } cout << *max_element(dp.cbegin(), dp.cend()) << "\n"; }