#include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const int mod = 1000000007;
const long long Lbig = 2e18;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
long long a[500011], b[500011];
int n, k;
long long cost;
set<pair<int, int> > st1, st2;
int calc(long long coef) {
  st1.clear();
  st2.clear();
  int cnt = 0;
  cost = 0;
  for (int i = 1; i <= n; i++) {
    long long upd1 = a[i] + b[i] + coef;
    long long upd2 = cnt + 1 == i ? Lbig : b[i] + st1.begin()->first + coef;
    long long upd3 = cnt == 0 ? Lbig : b[i] + st2.begin()->first;
    if (upd1 > 0 && upd2 > 0 && upd3 > 0) {
      st1.insert(make_pair(a[i], i));
      continue;
    } else if (upd1 <= upd2 && upd1 <= upd3) {
      st2.insert(make_pair(-b[i], i));
      cost += upd1;
      cnt++;
    } else if (upd2 <= upd1 && upd2 <= upd3) {
      st2.insert(make_pair(-b[i], i));
      st1.erase(st1.begin());
      st1.insert(make_pair(a[i], i));
      cost += upd2;
      cnt++;
    } else {
      st1.insert(make_pair(a[i], i));
      st2.erase(st2.begin());
      st2.insert(make_pair(-b[i], i));
      cost += upd3;
    }
  }
  return cnt;
}
int main() {
  n = getnum(), k = getnum();
  for (int i = 1; i <= n; i++) a[i] = getnum();
  for (int i = 1; i <= n; i++) b[i] = getnum();
  long long l = -Imx, r = Imx;
  while (l <= r) {
    long long m = l + r >> 1;
    int curk = calc(m);
    if (curk >= k)
      l = m + 1;
    else
      r = m - 1;
  }
  calc(r);
  cout << cost - r * k << endl;
  return 0;
}
