感觉没毛病,为啥就ac了一个?,求大佬看一下

P1678 烦恼的高考志愿

QLUzongyuxing @ 2022-01-19 10:11:56

#include<bits/stdc++.h>
using namespace std;
const int MAXN=1000000;
long long m,n,e=0;
long long a[MAXN],b[MAXN];
int main()
{
    scanf("%lld%lld",&m,&n);
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int j=0;j<n;j++){
        cin>>b[j];
    }
    for(int i=0;i<n;i++){
        long long l=0,r=m-1,d=1000000;
        while(l<=r){
            long long c=0;
            long long mid=(l+r)>>1;
            if(a[mid]>b[i]){
              c=a[mid]-b[i];
              r=mid-1;
            }else{
                c=b[i]-a[mid];
                l=mid+1;
            }
            if(d>c) d=c;    
        }
        e+=d;
    }
    cout<<e<<endl;
    return 0;
} 

by c21075 @ 2022-01-19 11:13:42

第17行 r=n-1;


|