#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, m, cnt;
long long sum, a[N], b[N];
bool check(long long x) {
  priority_queue<pair<int, int> > q;
  cnt = 0, sum = 0;
  for (int i = 1, iE = n; i <= iE; i++) {
    q.push(make_pair(-a[i] + x, 1));
    if (b[i] - q.top().first < 0)
      cnt += q.top().second, sum += b[i] - q.top().first, q.pop(),
          q.push(make_pair(b[i], 0));
  }
  return cnt <= m;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, iE = n; i <= iE; i++) scanf("%lld", &a[i]);
  for (int i = 1, iE = n; i <= iE; i++) scanf("%lld", &b[i]);
  long long l = 0, r = 2e9, ans = 0;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      ans = sum + m * mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%lld\n", ans);
  return 0;
}
