#include<bits/stdc++.h>
using namespace std;
#define fr(i,z) for(int i = 1; i <= z; i++)
const int N = 500500;
int n,k,j = 1;
int p[N],w[N];
long long ans;
priority_queue<int > t;
priority_queue<int,vector<int>,greater<int> > q;
bool cmp(int a,int b){return a>b;}
int main(){
scanf("%d%d",&n,&k);
fr(i,n) scanf("%d",p + i);
fr(i,n) scanf("%d",w + i);
sort(p + 1, p + n + 1, cmp);
sort(w + 1, w + n + 1, cmp); //要从大到小比较,为了获得能满足要求的最小功率的灯泡
fr(i,n){
while(p[j] >= w[i]) q.push(p[j++]); //把可以满足的都扔进堆里
if(!q.empty()){
ans += q.top();
t.push(q.top() - w[i]); //要记下差值,以便后面换灯泡
q.pop();
continue;
}
k--; //计数,判断是否无解 以及 最后剩余的可更换数
ans += w[i]; //如果确定要换,那肯定是换等于需求功率的
if(k < 0) { //判断无解
cout << "NIE";
return 0;
}
}
while(k--){
ans -= t.top(); //换的思路都是相同的
t.pop();
}
printf("%d",ans);
}