Subtask #1 WA

P1678 烦恼的高考志愿

tangyiqi @ 2024-12-21 20:41:12

在这里就过了,但Subtask #1死活过不了

#include <bits/stdc++.h>
using namespace std;
int a[100005],ans,m;
int binary_search(int x){
    int l = 1,r = m,mid,res = a[m];
    while(l<=r){
        mid = l+((r-l)>>1);
        if(a[mid] == x)return 0;
        else if(a[mid]<x){
            res = min(res,x-a[mid]);
            l = mid+1;
        }
        else{
            res = min(res,a[mid]-x);
            r = mid-1;
        }
    }
    return res;
}
int main(){
    int n,ans = 0,small,x;
    scanf("%lld%d",&m,&n);
    for(int i = 1;i<=m;i++)scanf("%d",&a[i]);
    sort(a+1,a+m+1);
    while(n--){
        scanf("%d",&x);
        ans+=binary_search(x);
    }
    printf("%d",ans); 
    return 0;
}

by Yae__Miko @ 2024-12-22 14:34:37

加上这个就好了(bushi

typedef int ll;

好吧开玩笑的,你没开longlong当然会WA


|