题解 | #装进肚子#
装进肚子
https://ac.nowcoder.com/acm/problem/14721
注意此题需要开longlong
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
inline ll read() {
ll x=0,w=1;char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*w;
}
#define maxn 1000000
struct Qkl{
int zao,wan,chazhi;
}qkl[100005];
bool cmp(Qkl a,Qkl b) {
return a.chazhi>b.chazhi;
}
int main() {
int n,k;cin>>n>>k;
for(int i=1;i<=n;i++) {
qkl[i].zao=read();
}
for(int j=1;j<=n;j++) {
qkl[j].wan=read();
qkl[j].chazhi=qkl[j].zao-qkl[j].wan;
}
sort(qkl+1,qkl+n+1,cmp);
// for(int i=1;i<=n;i++) {
// cout<<qkl[i].chazhi<<" ";
// }
ll sum=0;
for(int i=1;i<=k;i++) {
sum+=qkl[i].zao;
}
for(int i=k+1;i<=n;i++) sum+=qkl[i].wan;
cout<<sum<<endl;
return 0;
}