为什么得分100还是unaccepted

P1678 烦恼的高考志愿

Yusiao @ 2024-03-19 13:07:37

#include<bits/stdc++.h>
using namespace std;

int main(){
    int m,n;
    cin>>m>>n;
    int i=0,j=0,a[m],b[n];
    for (i = 0; i < m; i++)
    {
        cin>>a[i];
    }
    for (j = 0; j < n; j++)
    {
        cin>>b[j];
    }
    sort(a,a+m);
    int k,sum=0;
    for (i = 0; i < n; i++)
    {
        k=lower_bound(a,a+m,b[i])-a;
        if (a[k]!=b[i])
        {
            if (b[i]<a[0])
            {
                sum+=a[k]-b[i];
            }
            else
            {
                sum+=min(abs(b[i]-a[k-1]),abs(a[k]-b[i]));
            }
        }
    }
    cout<<sum;
    return 0;
}

by Yusiao @ 2024-03-19 13:09:20


by GoodLuckCat @ 2024-03-19 13:09:54

@Yusiao 有一组 0 分的数据没过


by GoodLuckCat @ 2024-03-19 13:10:18

另外不要用本地图片地址


by Yusiao @ 2024-03-19 13:17:38


by Yusiao @ 2024-03-19 21:25:03

我自己来解释一下为什么,因为最后输出要用long long型


by Renoil_Benjamin @ 2024-03-26 13:19:51

@Yusiao 加特判即可 if(m==1&&n==100000)\ {\ cout<<"100000000000";\ return 0;\ }


by Answerexploer @ 2024-03-27 16:36:35

十年oi一场空,不开longlong见祖宗


|