100分求助,最后一个过不去

P1678 烦恼的高考志愿

seele_waiting @ 2022-12-24 21:03:53

#include<bits/stdc++.h>
using namespace std;

int a[100010],b[100010],n,m;
int main(){
    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);
    int ans=0;
    for(int i=1;i<=m;i++){
        int l=0,r=n+1;
        while(l<r){
            int mid=(l+r)/2;
            if(a[mid]<=b[i]){
                l=mid+1;
            }else{
                r=mid;
            }
        }
        if(b[i]<=a[1]) ans+=(a[1]-b[i]);
        else{
            ans+=min(abs(a[l-1]-b[i]),abs(a[l]-b[i]));
        }
    }
    cout<<ans;
}

by qingche_ @ 2022-12-26 16:21:42

不开long long见祖宗orz


by Fischl322 @ 2023-01-07 12:31:34

十年oi一场空 不开..


by OwenTZC @ 2023-01-09 11:09:27

@wanyuanshenma2 我记得long long,但把m,n给搞混了(寄


by FrankFrank @ 2023-01-26 11:32:36

十年oi一场空,不开long long见祖宗


by whc2011 @ 2023-01-29 20:41:45

long long


by zzf12345666 @ 2023-02-06 00:13:58

long long


|