#1没过,我直接#define int long long为啥不行呢

P1678 烦恼的高考志愿

ggbondddd @ 2024-10-20 20:14:06

#include<iostream>
#include<math.h>
#include<algorithm>
#define int long long
using namespace std;
int bi(int q[],int l,int r,int k){
    while(l+1!=r){
        int mid=l+r>>1;
        if(q[mid]<=k)l=mid;
        else r=mid;
    }
    if(abs(k-q[r])>abs(k-q[l]))return abs(k-q[l]);
    else return abs(k-q[r]);
}
signed main()
{
    int n,m,s=0;
    int a[100010],b[100010];
    cin>>n>>m;
    for(int i=0;i<n;i++){cin>>a[i];}
    for(int i=0;i<m;i++){cin>>b[i];}
    sort(a,a+n);
    for(int i=0;i<m;i++)
    {
        s+=bi(a,-1,n,b[i]);
    }
    cout<<s;
}

by weizhiheng @ 2024-10-20 20:16:04


by ggbondddd @ 2024-10-20 21:12:00

@weizhiheng 大佬求教(诚恳


|