Miracle1024 @ 2023-05-07 13:52:58
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int mian;
int n,a[114514]={0},b[114514]={0},l,r;
ll ans=0;
int er(int k){
l=1;
r=mian;
while(l<r){
int m=(l+r+1)/2;
if(a[m]<k) l=m;
else r=m-1;
}
return l;
}
const int maxx=0x3f3f3f,minn=-0x3f3f3f;
int main(){
// freopen("doc.in","r",stdin);
// freopen("doc.out","w",stdout);
cin>>mian>>n;
for(int i=1;i<=mian;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
sort(a+1,a+mian+1);
for(int i=1;i<=n;i++){
int t=er(b[i]);
ans+=min(abs(a[t]-b[i]),abs(a[t+1]-b[i]));
}
printf("%lld",ans);
return 0;
}
by wangzih123 @ 2023-07-18 16:08:32
@yee1024pi emm...你把剩下变量的int也改成long long吧,看看能不能过