#include <bits/stdc++.h>
#pragma GCC optimize(2, "Ofast", "inline", "-fgcse", "-fgcse-lm", "-fipa-sra", \
                     "-ftree-pre", "-ftree-vrp", "-fpeephole2", "-ffast-math", \
                     "-fsched-spec", "unroll-loops", "-falign-jumps",          \
                     "-falign-loops", "-falign-labels", "-fdevirtualize",      \
                     "-fcaller-saves", "-fcrossjumping", "-fthread-jumps",     \
                     "-funroll-loops")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
char BB[1 << 20], *SS = BB, *TT = BB;
inline int read() {
  int s = 0;
  char ch =
      (SS == TT && (TT = (SS = BB) + fread(BB, 1, 1 << 20, stdin), SS == TT)
           ? EOF
           : *SS++);
  while (!((ch >= '0') && (ch <= '9')))
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, 1 << 20, stdin), SS == TT)
              ? EOF
              : *SS++);
  while (((ch >= '0') && (ch <= '9')))
    s = (s << 3) + (s << 1) + (ch ^ 48),
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, 1 << 20, stdin), SS == TT)
              ? EOF
              : *SS++);
  return s;
}
const int maxn = 500005;
int n, k, a[maxn], b[maxn];
priority_queue<pair<int, int>> q;
int main() {
  int n = read(), k = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) b[i] = read();
  long long l = 0, r = 2e9, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    long long s = 0;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      q.push(make_pair(-a[i], 0));
      int tmp = b[i] - mid - q.top().first;
      if (tmp < 0) s += tmp, q.pop(), q.push(make_pair(b[i] - mid, 1));
    }
    while (!q.empty()) cnt += q.top().second, q.pop();
    if (cnt == k) {
      printf("%lld\n", s + 1ll * k * mid);
      return 0;
    }
    if (cnt < k)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return 0;
}
