rainbow_cat @ 2022-04-10 15:56:52
70分!QAQ
#include<bits/stdc++.h>
using namespace std;
int a[100000],b[100000],ans=0;
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=m;i++)
{
cin>>b[i];
}
sort(a+1,a+n+1);
for(int i=1;i<=m;i++)
{
int fz=a[lower_bound(a,a+n,b[i])-a];
int fz2=a[(lower_bound(a,a+n,b[i]))-a-1];
if(abs(fz-b[i])>abs(b[i]-fz2))
{
ans+=abs(b[i]-fz2);
}
else
{
ans+=abs(fz-b[i]);
}
}
cout<<ans;
return 0;
}
by l_h_l @ 2022-05-31 22:31:53
没特判