救救蒟蒻吧,10分求助!!

P1678 烦恼的高考志愿

Allen_yang @ 2022-10-18 14:38:48

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
long long x[100005],s;
int main() {
    int m,n;
    long long ans=0;
    cin >> m >> n;
    for(int i=1; i<=m; i++)cin >> x[i];
    sort(x+1,x+1+n);
    for(int i=1; i<=n; i++) {
        cin >>s;
        int k=lower_bound(x+1,x+1+n,s)-x;
        int k2=k-1;
        long long c=1e9,d=1e9;
        if(k<=m){
            c=x[k]-s;
        }
        if(k2>0){
            d=s-x[k2];
        }
        ans+=min(c,d);
    }
    cout << ans;
    return 0;
}

除了测试#1.1号点,其他全wa


by Allen_yang @ 2022-10-18 14:39:28

说错了,#1的最后一个点


|