Subtask #1对了,其他全WA,悬关,跪求daola求解。

P1678 烦恼的高考志愿

Very_Smart_Honet @ 2023-11-02 23:38:17

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
int n,m;
int lu[1000010];
int xue[1000010];
int ans;
int check(int x,int y)
{
    return abs(lu[x]-xue[y]);
}
signed main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>lu[i];
    }
    for(int i=1;i<=m;i++)
    {
        cin>>xue[i];
    }
    sort(lu+1,lu+n+1);
    for(int i=1;i<=m;i++)
    {
        int l=1,r=n;
        int k=(1+n)>>1;
        int p=abs(lu[k]-xue[i]);
        //cout<<p<<endl;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(check(mid,i)<=p)
            {
                p=abs(lu[mid]-xue[i]);
                if(lu[mid]>=xue[i]) r=mid-1;
                else l=mid+1;
            }
            else
            {
                l=mid+1;
            }
        }
        //cout<<p<<endl<<endl;      
        ans+=p;
    }
    cout<<ans<<endl;
    return 0;
}

dalao们帮忙看看


by Brainless_zxc @ 2023-12-29 15:06:34

@wangzihang2012 你谁啊


by Very_Smart_Honet @ 2023-12-29 15:17:37

@wangzihang2012 好好好


|