#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct rec {
  long long v;
  int inc;
};
multiset<rec> tr;
multiset<rec>::iterator it;
bool operator<(rec a, rec b) { return a.v < b.v; }
long long tmp, l, r, mid;
int a[N], b[N], cnt, n, K, i;
void run(int x) {
  tmp = cnt = 0;
  tr.clear();
  for (i = 1; i <= n; i++) {
    tr.insert({a[i] - x, 1});
    it = tr.begin();
    if ((*it).v + b[i] < 0) {
      tmp += (*it).v + b[i];
      cnt += (*it).inc;
      tr.erase(it);
      tr.insert({-b[i], 0});
    }
  }
}
int main() {
  scanf("%d %d", &n, &K);
  for (i = 1; i <= n; i++) scanf("%d", a + i);
  for (i = 1; i <= n; i++) scanf("%d", b + i);
  l = 0;
  r = 2e9;
  while (l < r) {
    mid = (l + r) / 2;
    run(mid);
    if (cnt < K) l = mid + 1;
    if (cnt > K) r = mid - 1;
    if (cnt == K) l = r = mid;
  }
  run(l);
  if (cnt != K) tmp += 1ll * (K - cnt) * l;
  tmp += K * l;
  printf("%lld", tmp);
}
