24KB24 @ 2022-07-07 15:59:16
#include<iostream>
#include<algorithm>
using namespace std;
int m,n,score;
int a[1001];
long long sum=0;
int main()
{
cin>>m>>n;
for(int i=1;i<=m;i++)
cin>>a[i];
sort(a+1,a+1+m);
for(int i=1;i<=n;i++)
{
cin>>score;
int left=0,right=m+1;
while(left<right)
{
int mid=left+(right-left)/2;
if(a[mid]>score)
right=mid;
else
left=mid+1;
}
if(score<=a[1])
{
sum+=a[1]-score;
}
else
sum+=min(abs(a[left]-score),abs(a[left-1]-score));
}
cout<<sum;
}
by 听取UKE声一片 @ 2022-07-07 16:03:11
@24KB24 您能看数据范围吗
by irris @ 2022-07-07 16:03:18
@24KB24
by 24KB24 @ 2022-07-07 16:03:27
我知道了,数组开小了
by 24KB24 @ 2022-07-07 16:04:03
@AlgorithmerSnow 谢谢,知道了
by 24KB24 @ 2022-07-07 16:04:25
@听取UKE声一片 谢谢,我知道了
by qw057488 @ 2022-08-02 10:08:31
@听取UKE声一片
by 听取UKE声一片 @ 2022-08-03 10:07:25
@qw057488 你什么意思?