#include <bits/stdc++.h>
using namespace std;
const int N = 500005, M = 100005, mod = 1e9 + 7;
template <class T>
inline void gmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <class T>
inline void gmax(T &x, const T &y) {
  if (x < y) x = y;
}
inline void ch(int &x, int y) { x = (x + y) % mod; }
const int BufferSize = 1 << 25;
char buffer[BufferSize], *Bufferhead, *Buffertail;
int Terminal;
inline char Getchar() {
  if (Bufferhead == Buffertail) {
    int l = fread(buffer, 1, BufferSize, stdin);
    if (!l) {
      Terminal = 1;
      return 0;
    }
    Buffertail = (Bufferhead = buffer) + l;
  }
  return *Bufferhead++;
}
template <class T>
inline bool read(T &x) {
  x = 0;
  char c = Getchar(), rev = 0;
  while (c < '0' || c > '9') {
    c = Getchar();
    rev |= c == '-';
    if (Terminal) return 0;
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = Getchar();
  x = rev ? -x : x;
  return 1;
}
template <class T>
inline void print(T x, const char c = '\n') {
  if (!x) {
    putchar('0');
    putchar(c);
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  int m = 0, a[20];
  while (x) a[m++] = x % 10, x /= 10;
  while (m--) putchar(a[m] + '0');
  putchar(c);
}
inline int exp(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = (long long)ans * x % mod;
    x = (long long)x * x % mod;
    y >>= 1;
  }
  return ans;
}
int n, k, a[N], b[N], c[N][3];
char p[N];
bool d[N][3];
pair<long long, int> calc(int mid) {
  long long ans = 0;
  int cnt = 0;
  priority_queue<pair<pair<int, bool>, int>,
                 vector<pair<pair<int, bool>, int> >,
                 greater<pair<pair<int, bool>, int> > >
      q;
  for (int i = 1; i <= n; i++) a[i] -= mid;
  for (int i = 1; i <= n; i++) p[i] = 0;
  for (int i = 1; i <= n; i++) {
    c[i][0] = b[i];
    d[i][0] = 0;
    ans += b[i];
    c[i][1] = min(0, b[i] + a[i]);
    d[i][1] = (c[i][1] < 0);
    c[i][2] = a[i];
    d[i][2] = 1;
  }
  for (int i = 1; i <= n; i++) {
    q.push(make_pair(make_pair(c[i][1] - c[i][0], d[i][1] ^ d[i][0]), i));
    pair<pair<int, bool>, int> t = q.top();
    q.pop();
    ans += t.first.first;
    cnt += t.first.second;
    p[t.second]++;
    if (p[t.second] == 1)
      q.push(make_pair(make_pair(c[t.second][2] - c[t.second][1],
                                 d[t.second][2] ^ d[t.second][1]),
                       t.second));
  }
  for (int i = 1; i <= n; i++) a[i] += mid;
  return make_pair(ans, cnt);
}
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]);
  int l = 0, r = 2e9 + 5;
  while (l < r) {
    int mid = ((long long)l + r + 1) >> 1;
    if (calc(mid).second > k)
      r = mid - 1;
    else
      l = mid;
  }
  print(calc(r).first + (long long)r * k);
  return 0;
}
