#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
int a[2505], b[2505];
long long ans;
priority_queue<pair<long long, int>, std::vector<pair<long long, int>>,
               std::greater<pair<long long, int>>>
    q;
int cal(long long x) {
  int cnt = 0;
  ans = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    q.push({a[i], 0});
    long long val = q.top().first;
    long long cur = b[i] - x;
    if (val + cur < 0) {
      ans += val + cur;
      q.pop();
      q.push({-cur, 1});
    }
  }
  while (!q.empty()) {
    cnt += q.top().second;
    q.pop();
  }
  return cnt;
}
void fmain(int tid) {
  scanf("%d%d", &n, &k);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", a + i);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", b + i);
  long long l = 0, r = 2e9;
  while (l <= r) {
    long long mid = (l + r) / 2;
    int z = cal(mid);
    if (z == k) {
      printf("%lld\n", ans + mid * k);
      return;
    }
    if (z > k)
      r = mid - 1;
    else
      l = mid + 1;
  }
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
