#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
void read(Tp &x) {
  x = 0;
  long long op = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') op = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= op;
}
template <typename Tp>
void CMax(Tp &x, Tp y) {
  if (y > x) x = y;
}
template <typename Tp>
void CMin(Tp &x, Tp y) {
  if (y < x) x = y;
}
const long long N = 500000 + 10;
const long long LIM = 2e9;
long long n, k;
long long a[N], b[N];
priority_queue<pair<long long, long long> > H;
pair<long long, long long> count(long long mid) {
  while (!H.empty()) H.pop();
  long long sum = 0, tot = 0;
  for (long long i = (1); i <= (n); ++i) {
    H.push(make_pair(mid - a[i], 1));
    long long v = b[i] - H.top().first;
    if (v <= 0) {
      sum += v;
      tot += H.top().second;
      H.pop();
      H.push(make_pair(b[i], 0));
    }
  }
  return make_pair(sum, tot);
}
signed main() {
  read(n);
  read(k);
  for (long long i = (1); i <= (n); ++i) read(a[i]);
  for (long long i = (1); i <= (n); ++i) read(b[i]);
  long long l = 0, r = LIM, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    pair<long long, long long> ck = count(mid);
    if (ck.second < k)
      l = mid + 1;
    else
      r = mid;
  }
  pair<long long, long long> ans = count(l);
  printf("%lld", ans.first + k * l);
  return 0;
}
