#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x, f = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') f = -1;
  for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';)
    x = (x << 3) + (x << 1) + c - '0';
  return x * f;
}
priority_queue<pair<long long, int> > pq;
int a[500000 + 5], b[500000 + 5];
int main() {
  int n, k, i, l = 0, r = 2e9, mid, cnt;
  long long x, s;
  n = read();
  k = read();
  for (i = 1; i <= n; ++i) a[i] = read();
  for (i = 1; i <= n; ++i) b[i] = read();
  while (l <= r) {
    mid = l + (r - l >> 1);
    for (s = cnt = 0, i = 1; i <= n; ++i) {
      pq.push(make_pair(-a[i], 0));
      x = b[i] - mid - pq.top().first;
      if (x < 0) s += x, pq.pop(), pq.push(make_pair(b[i] - mid, 1));
    }
    while (!pq.empty()) cnt += pq.top().second, pq.pop();
    if (cnt == k) return 0 * printf("%I64d", s + 1LL * k * mid);
    if (cnt < k)
      l = mid + 1;
    else
      r = mid - 1;
  }
}
