#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
long long int a[maxn], b[maxn], va[maxn], vb[maxn], verse[maxn];
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%I64d", &b[i]);
  long long int ans = 0;
  b[n] = 1e+18;
  while (k--) {
    int ra = -1, rb;
    for (int i = n - 1, j = n, minb = n; i >= 0; i--) {
      if (j > i) j = i;
      if (b[j] < b[minb] && !vb[j]) minb = j;
      while ((j - 1) >= 0 && verse[j - 1])
        if (b[--j] < b[minb] && !vb[j]) minb = j;
      if (!va[i] && (ra == -1 || a[i] + b[minb] < a[ra] + b[rb]))
        ra = i, rb = minb;
    }
    ans += a[ra] + b[rb];
    va[ra]++;
    vb[rb]++;
    for (int i = ra; i < rb; i++) verse[i]++;
    for (int i = rb; i < ra; i++) verse[i]--;
  }
  printf("%I64d\n", ans);
  return 0;
}
