Subtask #1WA大佬求调

P1678 烦恼的高考志愿

zhizhenyaohanyu @ 2024-07-13 19:10:18

#include<bits/stdc++.h>
using namespace std;
int a[1000010],x,n,s=0,m;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>m>>n;
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    sort(a,a+m);
    for(int i=0;i<n;i++){
        cin>>x;
        if(x<=a[0]) s=s+a[0]-x;
        else if(x>=a[m-1]) s=s+x-a[m-1];
        else{
            int l,r,mid;
            l=0;r=m-1;
            while(l<=r){
                mid=(l+r)/2;
                if(a[mid]>=x) r=mid-1;
                else if(a[mid<x]) l=mid+1;
            }
            int t=min(a[l]-x,x-a[l-1]);
            s+=t;
        }
    }
    cout<<s;
}

by stylus @ 2024-07-13 19:18:11

@zhizhenyaohanyu hack没过很正常,记得开longlong


by stylus @ 2024-07-13 19:19:23

@zhizhenyaohanyu 还有,你没看讨论区?


by zhizhenyaohanyu @ 2024-07-13 19:22:31

@5520qq 谢谢大佬


by __F__ @ 2024-07-13 19:29:59

@zhizhenyaohanyu 人机


by zhizhenyaohanyu @ 2024-07-13 19:31:57

@yuhan09 ???


by cgxd @ 2024-07-13 19:46:24

10年OI一场空,不开____见祖宗


by zhizhenyaohanyu @ 2024-07-13 19:56:22

@cgxd long long


by cgxd @ 2024-07-13 19:59:16

@zhizhenyaohanyu 不过这题long long有点危险,建议开unsigned long long


by zhizhenyaohanyu @ 2024-07-13 20:01:15

@cgxd 開long long剛好過的


by cgxd @ 2024-07-13 20:02:24

@zhizhenyaohanyu 那就没事了


|