#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<long long> energies;
vector<long long> prices;
vector<long long> dp_sum;
vector<long long> dp_answer;
vector<long long> max_dp_take_before;
vector<long long> min_prices;
long long answer = 0;
void In() {
  cin >> n >> k;
  energies.resize(n);
  prices.resize(n);
  for (int i = 0; i < n; i++) cin >> energies[i];
  for (int i = 0; i < n; i++) cin >> prices[i];
}
void Update(long long value) { answer = max(answer, value); }
void Solve() {
  dp_sum = energies;
  for (int i = n - 2; i >= 0; i--) dp_sum[i] += dp_sum[i + 1];
  dp_answer.resize(n);
  dp_answer.back() = max(0LL, energies.back() - prices.back());
  for (int i = n - 2; i >= 0; i--)
    dp_answer[i] = max(dp_sum[i] - prices[i], dp_answer[i + 1]);
  max_dp_take_before.resize(n);
  max_dp_take_before.front() = dp_sum[0] - prices[0];
  for (int i = 1; i < n; i++)
    max_dp_take_before[i] =
        max(max_dp_take_before[i - 1], dp_sum[i] - prices[i]);
  min_prices = prices;
  for (int i = 1; i < n; i++)
    min_prices[i] = min(min_prices[i], min_prices[i - 1]);
  if (k == 0)
    Update(dp_answer[0]);
  else if (k == 1) {
    for (int i = 1; i < n - 1; i++) {
      long long cycle = max(0LL, dp_sum[0] - dp_sum[i + 1] - min_prices[i]);
      Update(cycle + dp_answer[i + 1]);
    }
    for (int i = 0, next = 2; next < n; i++, next++) {
      Update(dp_answer[next]);
      Update(dp_sum[i + 1] - prices[i + 1]);
      long long add = max(0LL, energies[i + 1] - prices[i + 1]);
      long long prev_best = max_dp_take_before[i] - energies[i + 1];
      Update(prev_best + add);
    }
  } else {
    Update(dp_sum[0] - min_prices[n - 2]);
    Update(energies.back() - prices.back());
  }
}
void Out() { cout << answer << '\n'; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  In();
  Solve();
  Out();
}
