附加测试点WA求助qwq

P1678 烦恼的高考志愿

Lizsama @ 2022-08-23 22:10:23

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<ctime>
#include<stack>
#include<queue>
using namespace std;
const int N=5e6+10;

int b[N],n,m,cnt,ans,a[N];

int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=m;i++)
        cin>>b[i];
    for(int i=1;i<=m;i++){
        int l=1,r=n;
        while(l<r-1){
            int mid=(l+r)>>1;
            if(a[mid]<=b[i])
                l=mid;
            else
                r=mid;
        }
        if(abs(b[i]-a[l])<abs(b[i]-a[r]))
            cnt=abs(b[i]-a[l]);
        else cnt=abs(b[i]-a[r]);
        ans+=cnt;
    }
    cout<<ans; 
}

by Failure_Terminator @ 2022-08-23 22:12:17

Cu Ball


by xzy090626 @ 2022-08-23 22:22:44

十年 OI 一场空,_____


by Composite_Function @ 2022-08-23 22:57:43

不开 long long 见祖宗


by AlexJi @ 2022-10-03 19:27:35

long long!!!!!!


|