#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "sz = " << vc.size() << endl << "[";
  for (const T& v : vc) o << v << ",";
  o << "]";
  return o;
}
int N, K;
const int MN = 500000;
long long a[MN], b[MN];
long long ans;
int agmn(long long off) {
  priority_queue<long long> usea;
  priority_queue<long long, vector<long long>, greater<long long>> leftb;
  long long sum = 0;
  for (int i = N - 1; i >= 0; i--) {
    leftb.push(b[i]);
    long long X = 0;
    long long Y = a[i] - off + leftb.top();
    long long Z = usea.empty() ? 1e10 : a[i] - usea.top();
    if (X <= Y && X <= Z) {
      sum += X;
    } else if (Y <= X && Y <= Z) {
      sum += Y;
      usea.push(a[i]);
      leftb.pop();
    } else {
      sum += Z;
      usea.pop();
      usea.push(a[i]);
    }
  }
  int agmn = usea.size();
  if (agmn <= K) {
    ans = sum + off * agmn;
  }
  return agmn;
}
int main() {
  cin >> N >> K;
  for (int i = 0; i < (int)(N); i++) cin >> a[i];
  for (int i = 0; i < (int)(N); i++) cin >> b[i];
  long long ub = 2e9, lb = 0;
  while (ub - lb > 1) {
    long long m = (ub + lb) / 2;
    if (agmn(m) <= K)
      lb = m;
    else
      ub = m;
  }
  cout << ans << endl;
}
