70pts已解决但是不知道为什么

P1678 烦恼的高考志愿

JiuZhE66666 @ 2023-10-14 17:05:04

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll m,n;
    scanf("%lld%lld",&m,&n);
    ll school[m+5]={0};
    ll score[n+5]={0};
    for(ll i=1;i<=m;i++)scanf("%lld",&school[i]);
    sort(school+1,school+m+1);
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        ll x;
        scanf("%d",&x);
        ll l=1,r=m+1,mins=1e10;
        while(l<=r)
        {
            ll mid=(l+r)/2;
            if(abs(school[mid]-x)<=abs(mins-x))mins=school[mid];
            if(school[mid]>=x)r=mid-1;
            else l=mid+1;
        }
        sum+=abs(mins-x);
    }
    printf("%lld\n",sum);
    return 0;
}

by JiuZhE66666 @ 2023-10-14 17:05:43

把l的初始值改为0就70分,改为1就a了


|