z1443888087 @ 2024-11-07 21:23:08
#include<iostream>
#include<algorithm>
using namespace std;
int n1[100005];
int m1[100005];
int main(){
int n=0,m=0,sum=0;//n时人数,m时学校
cin>>m>>n;
for(int i=1;i<=n;i++)cin>>n1[i];
for(int i=1;i<=m;i++)cin>>m1[i];
sort(m1+1,m1+1+m);
for(int i=1;i<=n;i++){
int l=0,r=m-1;
int tot=1e9;
while(l<=r){
int mid=l+(r-l)/2;;
if(m1[mid]==n1[i]){
tot=0;
break;
}
else if(m1[mid]<n1[i]){
tot=min(tot,abs(m1[mid]-n1[i]));
l=mid+1;
}
else if(m1[mid]>n1[i]){
tot=min(tot,abs(m1[mid]-n1[i]));
r=mid-1;
}
}
sum+=tot;
}
cout<<sum;
}
by __yun__ @ 2024-11-07 21:33:25
@z1443888087 没有return 0
by z1443888087 @ 2024-11-07 21:34:58
@yun 不行,加了return 0也是全WA