roooot4 @ 2020-09-22 19:37:19
#include<bits/stdc++.h>
using namespace std;
int a[10000001];
int main ()
{
int n,m,s=0,l,r,mid,t;
scanf("%d %d",&m,&n);
for(int i=1;i<=m;i++)
scanf("%d",&a[i]);
sort(a+1,a+m+1);
while(n--)
{
scanf("%d",&t);
l=1;r=m;
while(l<=r)
{
mid=(l+r)/2;
if(a[mid]==t)
{
r=mid;
break;
}
if(a[mid]<t)
l=mid+1;
else
r=mid-1;
}
s=s+min(abs(a[r]-t),abs(a[l]-t));
printf("%d ",s);
}
printf("%d",s);
return 0;
}
3,8,10没有过,3算出来的结果比答案还要小【捂脸】
by Wu_Ren @ 2020-09-22 19:58:28
2 1
300 600
110
答案是 190
,你是 110
一天能看到两个人同一题错同一个地方就离谱
by _Yoimiya_ @ 2020-09-22 19:58:57
if(b[i]<=a[1]) ans+=a[1]-b[i];
特判之后行不行
by roooot4 @ 2020-09-25 20:20:39
@Wu_Ren 啊,谢啦