#include <bits/stdc++.h>
using namespace std;
int N, K;
long long a[500500], b[500500], res;
pair<long long, int> f(long long X) {
  long long ans = 0;
  int anum = 0;
  priority_queue<long long> q, bq;
  for (int i = (0); i < (N); i++) {
    q.push(-a[i]);
    long long o1 = -q.top() + b[i] - X;
    long long o2 = bq.size() ? b[i] - bq.top() : (long long)1e18;
    if (o1 < o2 && o1 < 0) {
      ans += -q.top() + b[i] - X;
      q.pop(), anum++;
      bq.push(b[i]);
    } else if (o2 <= o1 && o2 < 0) {
      ans -= bq.top();
      bq.pop(), bq.push(b[i]);
      ans += b[i];
    }
  }
  return make_pair(ans, anum);
}
int main() {
  if (1) {
    scanf("%d %d", &N, &K);
    for (int i = (0); i < (N); i++) scanf("%lld", &a[i]);
    for (int i = (0); i < (N); i++) scanf("%lld", &b[i]);
  } else {
    srand(time(NULL));
    N = 2200, K = rand() % N;
    for (int i = (0); i < (N); i++)
      a[i] = rand() % N + 5, b[i] = rand() % N + 5;
    for (int i = (0); i < (N); i++) printf("%lld %lld\n", a[i], b[i]);
  }
  long long lo = 0, hi = 1e13;
  while (lo < hi) {
    long long X = (lo + hi + 1) / 2;
    pair<long long, int> p = f(X);
    long long anum = p.second;
    if (anum > K) {
      hi = X - 1;
    } else {
      lo = X;
    }
  }
  res = f(lo).first + K * lo;
  printf("%lld\n", res);
  return 0;
}
