#include <bits/stdc++.h>
using namespace std;
int n, k;
int exc[100020], req[100020];
void solve0() {
  long long sufsum = 0;
  long long answer = 0;
  for (int i = n - 1; i >= 0; i--) {
    sufsum += exc[i];
    answer = max(answer, sufsum - req[i]);
  }
  cout << answer << '\n';
}
void solve1() {
  long long answer = 0;
  answer = max(answer, accumulate(exc, exc + n - 1, 0LL) -
                           *min_element(req, req + n - 1) +
                           max(0, exc[n - 1] - req[n - 1]));
  answer = max(answer, accumulate(exc, exc + n, 0LL) -
                           *min_element(exc + 1, exc + n) - req[0]);
  long long sufsum = 0;
  for (int i = n - 1; i > 0; i--) {
    sufsum += exc[i];
    answer = max(answer, sufsum - req[i]);
  }
  sufsum += exc[0];
  long long prefsum = 0;
  int prefmin = req[0];
  for (int i = 0; i < n - 1; i++) {
    prefmin = min(prefmin, req[i]);
    prefsum += exc[i];
    sufsum -= exc[i];
    answer = max(answer, prefsum - prefmin + sufsum - req[i + 1]);
  }
  cout << answer << '\n';
}
void solve2() {
  cout << max(0LL, max(0LL + exc[n - 1] - req[n - 1],
                       accumulate(exc, exc + n, 0LL) -
                           *min_element(req, req + n - 1)))
       << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> exc[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> req[i];
  }
  if (k == 0) {
    solve0();
  }
  if (k == 1) {
    solve1();
  }
  if (k >= 2) {
    solve2();
  }
}
