#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
const long long inf = 1e11;
namespace IO_ReadWrite {
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <typename T>
inline void read(T &x) {
  x = 0;
  register T f = 1;
  register char c =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
           ? EOF
           : *p1++);
  while (c > 57 || c < 48) {
    if (c == '-') f = -1;
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  }
  while (c >= 48 && c <= 57) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  }
  x *= f;
  return;
}
inline void ReadChar(char &c) {
  c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
           ? EOF
           : *p1++);
  while (!isalpha(c))
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
}
template <typename T>
inline void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar('0' + x % 10);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
}  // namespace IO_ReadWrite
using namespace IO_ReadWrite;
long long n, k, ans, cnt, sum, l = -inf, r = inf;
long long a[maxn], b[maxn];
struct node {
  long long first;
  bool second;
  bool operator<(const node &x) const { return first > x.first; }
};
bool check(long long x) {
  priority_queue<node> q;
  cnt = sum = 0;
  for (register int i = 1; i <= n; i++) {
    q.push({a[i], 0});
    int val = q.top().first;
    if (val + b[i] + x <= 0) {
      sum += (val + b[i] + x);
      if (!q.top().second) cnt++;
      q.pop();
      q.push({-b[i] - x, 1});
    }
  }
  return cnt >= k;
}
int main() {
  read(n);
  read(k);
  for (register int i = 1; i <= n; i++) read(a[i]);
  for (register int i = 1; i <= n; i++) read(b[i]);
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  check(ans);
  writeln(sum - ans * k);
  return 0;
}
