#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int read() {
  int x = 0, w = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
  return x * w;
}
const int N = 5e5 + 10;
struct Node {
  long long val;
  int typ;
  Node(long long _val = 0, int _typ = 0) {
    val = _val;
    typ = _typ;
  }
  bool operator<(const Node &tmp) const { return val < tmp.val; }
};
int n, k;
long long a[N], b[N], sav_sum = 0;
priority_queue<Node> q;
int check(long long del) {
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    Node t(-a[i], 0);
    q.push(t);
    Node now = q.top();
    long long tmp = b[i] - del - now.val;
    if (tmp < 0) {
      sum += tmp;
      q.pop();
      q.push(Node(b[i] - del, 1));
    }
  }
  int cnt = 0;
  sav_sum = sum;
  while (!q.empty()) {
    cnt += (q.top().typ == 1);
    q.pop();
  }
  return cnt;
}
int main() {
  n = read();
  k = 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 = 3e9, ans = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    int now = check(mid);
    if (now <= k)
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  check(ans);
  printf("%lld\n", sav_sum + ans * k);
  return 0;
}
