#include <bits/stdc++.h>
using namespace std;
struct meg {
  long long val;
  int flw;
  friend bool operator<(const meg& a, const meg& b) {
    return a.val > b.val || a.val == b.val && a.flw > b.flw;
  }
};
priority_queue<meg> q;
int n, m, a[500005], b[500005];
long long ans;
inline int read() {
  int n = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    n = n * 10 + c - '0';
    c = getchar();
  }
  return n * f;
}
int main() {
  register int L, R, mid, i, j, lt, sm;
  n = read();
  m = read();
  for (i = 1; i <= n; ++i) a[i] = read();
  for (i = 1; i <= n; ++i) b[i] = read();
  for (L = 1, R = 2e9; L <= R;) {
    mid = L + (R - L >> 1);
    sm = 0;
    ans = 0;
    while (!q.empty()) q.pop();
    for (i = 1; i <= n; ++i) {
      q.push((meg){a[i], 0});
      lt = b[i] - mid;
      if (lt + q.top().val < 0) {
        ans += lt + q.top().val;
        q.pop();
        q.push((meg){-lt, 1});
      }
    }
    while (!q.empty()) {
      sm += q.top().flw;
      q.pop();
    }
    if (sm == m) return 0 * printf("%I64d", ans + 1LL * m * mid);
    if (sm < m)
      L = mid + 1;
    else
      R = mid - 1;
  }
}
