#include <bits/stdc++.h>
using namespace std;
inline int readInt() {
  static int n, ch;
  n = 0, ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
  return n;
}
const int MAX_N = 500000 + 3;
int n, k, a[MAX_N], b[MAX_N];
struct Data {
  long long val;
  bool isA;
  Data(long long val, bool isA) : val(val), isA(isA) {}
  bool operator<(const Data &ano) const {
    return val > ano.val || (val == ano.val && isA < ano.isA);
  }
};
priority_queue<Data> pq;
long long sum = 0;
int check(int t) {
  while (!pq.empty()) pq.pop();
  int cnt = 0;
  sum = 0;
  for (int i = 0; i < n; ++i) {
    pq.push(Data(a[i] - t, true));
    if (pq.top().val + b[i] < 0) {
      cnt += pq.top().isA;
      sum += pq.top().val + b[i];
      pq.pop();
      pq.push(Data(-b[i], false));
    }
  }
  return cnt;
}
int main() {
  n = readInt(), k = readInt();
  for (int i = 0; i < n; ++i) a[i] = readInt();
  for (int i = 0; i < n; ++i) b[i] = readInt();
  int l = 0, r = 2e9 + 3;
  while (r - l > 1) {
    int mid = ((long long)l + r) / 2;
    if (check(mid) <= k)
      l = mid;
    else
      r = mid;
  }
  check(l);
  printf("%I64d\n", sum + (long long)k * l);
  return 0;
}
