pbr806 @ 2024-11-15 19:52:59
#include<bits/stdc++.h>
using namespace std;
int main(){
long long m,n,a[100005],b[100005],sum=0;
cin>>m>>n;
for(int i=0;i<m;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
}
for(int i=0;i<n;i++){
int min=999999;
for(int j=0;j<m;j++){
if(abs(b[i]-a[j])<min){
min=abs(b[i]-a[j]);
}
}
sum+=min;
}
cout<<sum;
return 0;
}
by zyt__dp @ 2024-11-15 19:53:44
@pbr806
这题要二分
by pbr806 @ 2024-11-16 12:41:51
@zyt__dp已过,谢谢提示