Alananan @ 2024-05-25 15:33:15
#include<iostream>
#include<cstdio>
using namespace std;
const int N = 1e5+10;
int a[N],n,m;
long long sum;
int find(int x){
int l = 1,r = n,mid;
while(l<r){
mid = (l + r) / 2;
if(a[mid] >= x){
r = mid;
}
else l = mid+1;
}
if(a[l] == x) return l;
}
int main(){
scanf("%d %d",&n,&m);
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
}
while(m--){
int k;
scanf("%d",&k);
int ans = find(k);
sum += min(k - a[ans],a[ans+1]-k);
}
printf("%ld\n",sum);
return 0;
}
麻烦问一下这段代码错在哪里了QAQ 蒟蒻不懂
by imJTya @ 2024-05-25 15:40:30
你最后一个输出把ld改成lld
by imJTya @ 2024-05-25 15:40:40
@Alananan