#include <bits/stdc++.h>
bool m1;
FILE *Input = stdin, *Output = stdout;
const int maxn = 5e5 + 5;
struct Pair {
  long long val;
  int cnt;
  Pair(){};
  Pair(long long ar1, int ar2) {
    val = ar1;
    cnt = ar2;
  }
  friend bool operator<(const Pair &ar1, const Pair &ar2) {
    return ar1.val == ar2.val ? ar1.cnt < ar2.cnt : ar1.val < ar2.val;
  }
} Min_Heap[maxn];
int Min_Top, a[maxn], b[maxn], n, k;
bool m2;
void Push(Pair ar1) {
  Min_Heap[++Min_Top] = ar1;
  for (int i = Min_Top; (i >> 1) > 0 && Min_Heap[i] < Min_Heap[i >> 1]; i >>= 1)
    std::swap(Min_Heap[i], Min_Heap[i >> 1]);
}
void Pop() {
  std::swap(Min_Heap[1], Min_Heap[Min_Top--]);
  for (int i = 1; (i << 1) <= Min_Top;) {
    i <<= 1;
    if ((i | 1) <= Min_Top && Min_Heap[i | 1] < Min_Heap[i]) i |= 1;
    if (Min_Heap[i] < Min_Heap[i >> 1])
      std::swap(Min_Heap[i], Min_Heap[i >> 1]);
    else
      break;
  }
}
Pair Get_ans(int ar1) {
  long long ans = 0;
  int anscnt = 0;
  Min_Top = 0;
  for (int i = 1; i <= n; i++) {
    Push(Pair(a[i], 0));
    long long nowval = b[i] + Min_Heap[1].val - ar1;
    if (nowval < 0) {
      ans += nowval;
      anscnt += (Min_Heap[1].cnt == 0);
      Pop();
      Push(Pair(ar1 - b[i], 1));
    }
  }
  return Pair(ans, anscnt);
}
long long Binary(int ar1, int ar2) {
  long long L = ar1 - 1, R = ar2 + 1, ans = -1;
  while (R > L + 1) {
    long long Mid = L + (R - L >> 1);
    Pair nowans = Get_ans(Mid);
    if (nowans.cnt <= k) {
      L = Mid;
      ans = nowans.val + 1LL * L * k;
    } else
      R = Mid;
  }
  return ans;
}
int main() {
  fscanf(Input, "%d %d", &n, &k);
  int Maxa = 0, Maxb = 0;
  for (int i = 1; i <= n; i++) {
    fscanf(Input, "%d", a + i);
    Maxa = std::max(Maxa, a[i]);
  }
  for (int i = 1; i <= n; i++) {
    fscanf(Input, "%d", b + i);
    Maxb = std::max(Maxb, b[i]);
  }
  fprintf(Output, "%lld\n", Binary(-Maxa - Maxb, Maxa + Maxb));
  fclose(Input);
  fclose(Output);
  return 0;
}
