#include using namespace std; //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") #define endl "\n" template inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } #ifndef LOCAL #define cerr if(false) cerr #endif #define out(x) #x << " = " << x << " " template ostream& operator<<(ostream &os, const pair &p) { return os << "(" << p.first << ", " << p.second << ")"; } template< typename T, typename B = decay()))>, typename enable_if::value>::type* = nullptr > ostream& operator<<(ostream &os, const T &c) { bool f = false; os << "("; for (const auto &x : c) { if (f) os << ", "; f = true; os << x; } return os << ")"; } typedef long long ll; const ll mod = 1000000007; const int MAX_N = 200000 + 10; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// struct Item { ll a, b, d; }; bool cmp(Item x, Item y){ return x.d > y.d; } std::vector compute_pref(const std::vector& v, int M) { int N = v.size(); std::vector pref(N+1, LLONG_MIN); std::priority_queue, greater> pq; ll sum = 0; for (int i = 0; i < N; i++) { pq.push(v[i].a); sum += v[i].a; if (pq.size() > M) { sum -= pq.top(); pq.pop(); } if (pq.size() == M) { pref[i+1] = sum; } } return pref; } std::vector compute_suff(const std::vector& v, int K) { int N = v.size(); std::vector suff(N+1, LLONG_MIN); std::priority_queue, greater> pq; ll sum = 0; for (int i = N-1; i >= 0; i--) { pq.push(v[i].b); sum += v[i].b; if (pq.size() > K) { sum -= pq.top(); pq.pop(); } if (pq.size() == K) { suff[i] = sum; } } return suff; } void solve() { int N, M, K; std::cin >> N >> M >> K; std::vector A(N), B(N); for (int i = 0; i < N; i++) std::cin >> A[i]; for (int i = 0; i < N; i++) std::cin >> B[i]; std::vector v(N); for (int i = 0; i < N; i++) { v[i] = {A[i], B[i], A[i] - B[i]}; } std::sort(v.begin(), v.end(), cmp); std::vector pref = compute_pref(v, M); std::vector suff = compute_suff(v, K); ll ans = 0; for (int i = M; i <= N - K; i++) { if (pref[i] != LLONG_MIN && suff[i] != LLONG_MIN) { chkmax(ans, pref[i] + suff[i]); } } std::cout << ans << endl; } signed main() { #ifndef LOCAL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); freopen("dodgeball2.in", "r", stdin); freopen("dodgeball2.out", "w", stdout); #endif int T = 1; while (T--) solve(); return 0; }