#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
// cf bits/extc++.h nonsense
#ifdef ONLINE_JUDGE
#define _EXT_CODECVT_SPECIALIZATIONS_H 1
#define _EXT_ENC_FILEBUF_H 1
#endif
#include "bits/extc++.h"
using namespace std;
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t;
((cerr << " | " << u), ...);
cerr << endl;
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
using ll = long long;
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
inline void init_io() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
out << "[";
for (int i = 0; i < sz(arr); i++) {
if (i) {
out << ", ";
}
out << arr[i];
}
return out << "]";
}
template <typename T>
struct PSA {
int n;
vector<T> psum;
template <typename U>
PSA(const vector<U>& arr) : n(sz(arr)), psum(n + 1) {
for (int i = 0; i < n; i++) {
psum[i + 1] = psum[i] + arr[i];
}
}
T query(int l, int r) const {
return psum[r] - psum[l];
}
};
template <typename T>
bool on(T mask, int bit) {
return (mask >> bit) & 1;
}
void solve() {
int n, kv;
cin >> n >> kv;
vector<long> costs(n), vals(n);
for (auto& a : costs) {
cin >> a;
}
for (auto& a : vals) {
cin >> a;
}
PSA<long> costs_psa(costs);
long buf1[kv + 1] alignas(1024), buf2[kv + 1] alignas(1024);
long *cdp alignas(1024) = buf1, *pdp alignas(1024) = buf2;
fill_n(cdp, kv + 1, -1e18);
fill_n(pdp, kv + 1, -1e18);
// vector<long> cdp(kv + 1, long(-1e18)), pdp(kv + 1, long(-1e18));
cdp[kv] = -costs_psa.psum[n];
// vector dp(n + 1, vector(kv + 1, long(-1e18)));
// for (int i = 0; i <= n; i++) {
// dp[i][kv] = -costs_psa.psum[i];
// }
long ans = -1e18;
for (int i = n - 1; i >= 0; i--) {
swap(cdp, pdp);
const int mx_iter = min(kv, (i + 16) & (~15));
// const int mx_iter = kv;
#pragma GCC ivdep
for (int j = max(0, (kv - (n - i) - 10) & (~15)); j < mx_iter; j++) {
cdp[j] = max(pdp[j], pdp[j + 1] + vals[i]);
}
ans = max(ans, cdp[0] + costs_psa.psum[i]);
cdp[kv] = -costs_psa.psum[i];
}
// for (int i = 0; i <= n; i++) {
// ans = max(ans, dp[i][0] + costs_psa.psum[i]);
// }
cout << ans << endl;
}
int main() {
init_io();
solve();
}