#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 1;
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  if (f) x = -x;
}
template <typename F>
inline void write(F x, char ed = '\n') {
  static short st[30];
  short tp = 0;
  if (x < 0) putchar('-'), x = -x;
  do st[++tp] = x % 10, x /= 10;
  while (x);
  while (tp) putchar('0' | st[tp--]);
  putchar(ed);
}
template <typename T>
inline void Mx(T &x, T y) {
  x < y && (x = y);
}
template <typename T>
inline void Mn(T &x, T y) {
  x > y && (x = y);
}
pair<long long, int> operator+(pair<long long, int> A, pair<long long, int> B) {
  return make_pair(A.first + B.first, A.second + B.second);
}
pair<long long, int> operator+(pair<long long, int> A, long long b) {
  return make_pair(A.first + b, A.second);
}
const int N = 1000500;
long long a[N], b[N], n, k;
pair<long long, int> check(long long val) {
  priority_queue<pair<long long, int> > q;
  pair<long long, int> ans(0, 0);
  for (int i = 1; i <= n; i++) {
    q.push(make_pair(-(a[i] + val), 1));
    pair<long long, int> t = q.top();
    t.first = -t.first;
    if (t.first + b[i] <= 0) {
      ans = ans + t + b[i], q.pop();
      q.push(make_pair(b[i], 0));
    }
  }
  return ans;
}
int main() {
  read(n), read(k);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 1; i <= n; i++) read(b[i]);
  long long l = -2e9, r = 2e9;
  while (l <= r) {
    int mid = (l + r) >> 1;
    pair<long long, int> tmp = check(mid);
    if (tmp.second >= k)
      l = mid + 1;
    else
      r = mid - 1;
  }
  pair<long long, int> tmp = check(r);
  write(tmp.first - (long long)k * r);
  return 0;
}
