90求助,#1本机正确但洛谷WA

P1678 烦恼的高考志愿

FanMingxuan @ 2023-07-13 19:52:03

在本机运行#1是对的但是在洛谷WA

本机运行结果:

#1数据

代码如下:

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

vector<long long>school;

int main() {
//  freopen("P1678_1.in","r",stdin);
    int m,n;
    long long tot = 0;
    scanf("%d %d",&m,&n);
    for(int i = 0; i < m; ++ i) {
        long long x;
        scanf("%lld",&x);
        school.push_back(x);
    }
    sort(school.begin(),school.end());
    for(int i = 0; i < n; ++ i) {
        long long x;
        scanf("%lld",&x);
        auto r = lower_bound(school.begin(),school.end(),x);
        if(r == school.end()) {
            advance(r,-1);
            tot += abs(*r - x);
        } else {
            auto l = r;
            advance(l,-1);
            tot += min(abs(*l - x),abs(*r - x));
        }
    }
    printf("%lld",tot);
}

by FanMingxuan @ 2023-07-13 19:56:10

看错了虽然是100但是是unaccept


|