#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, m, a[500050], b[500050];
pair<long long, int> check(long long x) {
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  int cnt = 0;
  long long all = 0;
  for (int i = 1; i <= n; ++i) {
    q.push({a[i] - x, 1});
    if (b[i] + q.top().first <= 0) {
      auto [w, t] = q.top();
      q.pop();
      all += b[i] + w;
      cnt += t;
      q.push({-b[i], 0});
    }
  }
  while (!q.empty()) q.pop();
  return make_pair(all, cnt);
}
int main() {
  n = read(), m = 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 = 1e12 + 1, ans = 0;
  while (l < r) {
    long long mid = (l + r) >> 1;
    auto [w, t] = check(mid);
    if (t <= m) {
      l = mid + 1, ans = w + mid * m;
    } else {
      r = mid;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
