#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 500;
const int INF = 1005000000;
struct Node {
  pair<int, int> ans1, ans2, tans2;
  int mil, mir;
  int tmil, tmir;
  int mis;
  Node() {}
  Node(const int &pos) {
    ans1 = make_pair(pos, pos);
    mil = mir = pos;
    ans2 = tans2 = make_pair(0, 0);
    mis = 0;
    tmir = 0;
    tmil = pos;
  }
} a[N << 1];
int tag[N << 1];
int wa[N], wb[N], n, K;
int mina(const int &x, const int &y) { return wa[x] < wa[y] ? x : y; }
int minb(const int &x, const int &y) { return wb[x] < wb[y] ? x : y; }
pair<int, int> minc(const pair<int, int> &x, const pair<int, int> &y) {
  return wa[x.first] + wb[x.second] < wa[y.first] + wb[y.second] ? x : y;
}
Node operator+(const Node &a, const Node &b) {
  Node ans;
  ans.ans1 = minc(minc(a.ans1, b.ans1), make_pair(a.mil, b.mir));
  ans.tans2 = minc(minc(a.tans2, b.tans2), make_pair(b.mil, a.mir));
  ans.ans2 = minc(a.ans2, b.ans2);
  ans.mil = mina(a.mil, b.mil);
  ans.mir = minb(a.mir, b.mir);
  if (a.mis < b.mis) {
    ans.mis = a.mis;
    ans.tmil = a.tmil;
    ans.tmir = minb(a.tmir, b.mir);
    ans.ans2 = minc(ans.ans2, b.tans2);
    ans.ans2 = minc(ans.ans2, make_pair(b.mil, a.tmir));
  } else if (a.mis > b.mis) {
    ans.mis = b.mis;
    ans.tmir = b.tmir;
    ans.tmil = mina(a.mil, b.tmil);
    ans.ans2 = minc(ans.ans2, a.tans2);
    ans.ans2 = minc(ans.ans2, make_pair(b.tmil, a.mir));
  } else {
    ans.mis = a.mis;
    ans.tmir = b.tmir;
    ans.tmil = a.tmil;
    ans.ans2 = minc(ans.ans2, make_pair(b.tmil, a.tmir));
  }
  return ans;
}
void build(int rot, int lt, int rt) {
  if (lt == rt) {
    a[rot] = Node(lt);
    return;
  }
  int mid = (lt + rt) >> 1;
  build(rot << 1, lt, mid), build(rot << 1 | 1, mid + 1, rt);
  a[rot] = a[rot << 1] + a[rot << 1 | 1];
}
void upd(int rot, int w) {
  tag[rot] += w;
  a[rot].mis += w;
}
void pushdown(int rot) {
  if (tag[rot]) {
    int t = tag[rot];
    tag[rot] = 0;
    upd(rot << 1, t), upd(rot << 1 | 1, t);
  }
}
void update(int rot, int lt, int rt, int lq, int rq, int w) {
  if (lq > rq) return;
  if (lt >= lq && rt <= rq) {
    upd(rot, w);
    return;
  }
  int mid = (lt + rt) >> 1;
  pushdown(rot);
  if (lq <= mid) update(rot << 1, lt, mid, lq, rq, w);
  if (rq > mid) update(rot << 1 | 1, mid + 1, rt, lq, rq, w);
  a[rot] = a[rot << 1] + a[rot << 1 | 1];
}
struct IO {
  char buf[1 << 23], *p1 = buf, *p2 = buf;
  int read() {
    char ch =
        (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
    int x = 0;
    while (ch < '0' || ch > '9')
      ch = (p1 == p2 &&
                    (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
                ? EOF
                : *p1++);
    while (ch >= '0' && ch <= '9')
      x = x * 10 + ch - 48,
      ch = (p1 == p2 &&
                    (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
                ? EOF
                : *p1++);
    return x;
  }
} io;
void print(const pair<int, int> &x) {
  cerr << x.first << " " << x.second << endl;
}
void print(int rot, int lt, int rt) {
  cerr << lt << " " << rt << " " << a[rot].mis << " " << a[rot].ans2.first
       << " " << a[rot].ans2.second << endl;
  if (lt == rt) return;
  int mid = (lt + rt) >> 1;
  pushdown(rot);
  print(rot << 1, lt, mid), print(rot << 1 | 1, mid + 1, rt);
}
int main() {
  n = io.read(), K = io.read();
  for (int i = 1; i <= n; i++) wa[i] = io.read();
  for (int i = 1; i <= n; i++) wb[i] = io.read();
  wa[0] = wb[0] = INF;
  build(1, 0, n);
  long long ans = 0;
  for (int i = 1; i <= K; i++) {
    pair<int, int> t = minc(a[1].ans1, a[1].ans2);
    ans += wa[t.first] + wb[t.second];
    wa[t.first] = wb[t.second] = INF;
    update(1, 0, n, t.first, t.first, 0),
        update(1, 0, n, t.second, t.second, 0);
    if (t.first <= t.second)
      update(1, 0, n, t.first, t.second - 1, 1);
    else
      update(1, 0, n, t.second, t.first - 1, -1);
  }
  cout << ans << endl;
}
