#include <bits/stdc++.h>
using namespace std;
int ara[500005], ara2[500005];
pair<long long, long long> func(long long v, int n) {
  long long ans = 0, cnt = 0;
  priority_queue<long long> q, q2;
  for (int i = 1; i <= n; i++) {
    q.push(-ara[i]);
    long long f = -q.top() + ara2[i] - v;
    long long d = (1LL << 55);
    if (q2.size()) {
      d = ara2[i] - q2.top();
    }
    if (d > 0 && f > 0) continue;
    if (d >= f) {
      ans += f;
      q.pop();
      q2.push(ara2[i]);
      cnt++;
    } else {
      ans += d;
      q2.pop();
      q2.push(ara2[i]);
    }
  }
  return make_pair(ans, cnt);
}
int main() {
  int i, j, k, l, m, n;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ara[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ara2[i]);
  }
  long long lo = -1e13, high = 0, ans = 1LL << 55;
  while (lo <= high) {
    long long mid = (lo + high) >> 1;
    pair<long long, long long> rs = func(-mid, n);
    if (rs.second >= k) {
      ans = rs.first - 1LL * k * mid;
      lo = mid + 1;
    } else
      high = mid - 1;
  }
  cout << ans << endl;
}
