#include <bits/stdc++.h>
inline long long rd() {
  long long _x = 0;
  int _ch = getchar(), _f = 1;
  for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
    ;
  if (_ch == '-') {
    _f = 0;
    _ch = getchar();
  }
  for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
  return _f ? _x : -_x;
}
void write(long long _x) {
  if (_x >= 10)
    write(_x / 10), putchar(_x % 10 + '0');
  else
    putchar(_x + '0');
}
inline void wrt(long long _x, char _p) {
  if (_x < 0) putchar('-'), _x = -_x;
  write(_x);
  if (_p) putchar(_p);
}
int k, n;
int a[500005], b[500005];
std::pair<int, long long> check(int x) {
  long long ans = 0;
  int tot = 0;
  std::priority_queue<std::pair<int, bool>, std::vector<std::pair<int, bool>>,
                      std::greater<std::pair<int, bool>>>
      que;
  for (int i = 1; i <= n; i++) {
    que.push({a[i], 1});
    int now = b[i] - x;
    if (now + que.top().first < 0) {
      ans += now + que.top().first;
      tot += que.top().second;
      que.pop();
      que.push({-now, 0});
    }
  }
  return {tot, 1ll * tot * x + ans};
}
int main() {
  n = rd(), k = rd();
  for (int i = 1; i <= n; i++) a[i] = rd();
  for (int i = 1; i <= n; i++) b[i] = rd();
  int l = 0, r = 2e9;
  while (l <= r) {
    int mid = ((long long)l + r) >> 1;
    int sum = check(mid).first;
    if (sum == k) {
      wrt(check(mid).second, '\n');
      return 0;
    }
    if (sum < k)
      l = mid + 1;
    else
      r = mid - 1;
  }
}
