求助!

P1678 烦恼的高考志愿

Viston @ 2018-08-12 20:46:29

lowerbound写的,感觉没毛病啊,可是只有70分,三个WA,又下不了数据,只好求助了QAQ

// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int a,b,c[100002],d,e,f,g,h,i,j,k,l;
long long ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b;
    for(i=1;i<=a;i++)
        cin>>c[i];
    sort(c+1,c+a+1);
    for(i=1;i<=b;i++)
    {
        cin>>d;
        e=lower_bound(c+1,c+a+1,d)-c;
        if(e==a+1)
        ans+=d-c[e-1];
        else
        ans+=min(c[e]-d,d-c[e-1]);
    }
    cout<<ans;
    return 0;
}

by Viston @ 2018-08-12 20:50:57

有人吗!!


by Viston @ 2018-08-12 20:54:37

现在写萌新刚学OI还有用吗...


by 追风少年σχ @ 2018-11-03 23:16:36

@Viston

if(e==1)ans+=(c[1]-d);

else ans+=min(c[e]-d,d-c[e-1]);


|