#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  bool f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
const int N = 5e5 + 10;
int n, K;
int a[N], b[N];
long long tot;
bool check(int mid) {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  int cnt = 0;
  tot = 0;
  for (int i = 1; i <= n; i++) {
    q.push({a[i] - mid, 0});
    if (q.top().first + b[i] <= 0) {
      tot += q.top().first + b[i];
      if (!q.top().second) cnt++;
      q.pop();
      q.push({-b[i], 1});
    }
  }
  return cnt >= K;
}
int main() {
  n = read(), K = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) b[i] = read();
  int l = 0, r = 2e9;
  while (l <= r) {
    int mid = ((long long)l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  check(l);
  printf("%lld\n", tot + (long long)K * l);
  return 0;
}
