#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f = ch == '-' ? -1 : f, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
const int LIM = 1000000000;
const int N = 500005;
int a[N], b[N];
pair<long long, bool> heap[N];
int n, K, tot;
long long ans;
void push(pair<long long, bool> x) {
  heap[++tot] = x;
  for (int fa, son = tot; son > 1; son = fa) {
    fa = son >> 1;
    if (heap[fa] < heap[son]) break;
    swap(heap[fa], heap[son]);
  }
}
void pop() {
  heap[1] = heap[tot--];
  for (int fa = 1, son; fa << 1 <= tot; fa = son) {
    son = fa << 1;
    if (son < tot && heap[son] > heap[son + 1]) ++son;
    if (heap[fa] < heap[son]) break;
    swap(heap[fa], heap[son]);
  }
}
int greedy(long long cst, long long &res) {
  int ret = 0;
  res = 0;
  tot = 0;
  for (int i = 1; i <= n; ++i) {
    push(make_pair(a[i], 1));
    pair<long long, bool> get = heap[1];
    if (get.first + b[i] - cst < 0) {
      res += get.first + b[i] - cst, ret += get.second;
      pop(), push(make_pair(-b[i] + cst, 0));
    }
  }
  return ret;
}
void convex_optimization() {
  int l = 0, r = LIM << 1, ret = 0;
  for (int mid; l <= r;) {
    long long tmp;
    mid = (long long)l + (long long)r >> 1;
    if (greedy(mid, tmp) <= K)
      ret = mid, ans = tmp, l = mid + 1;
    else
      r = mid - 1;
  }
  ans += 1ll * ret * K;
}
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();
  convex_optimization(), printf("%I64d\n", ans);
  return 0;
}
