样例3和样例9WA了,找不出问题
查看原帖
样例3和样例9WA了,找不出问题
241641
CRISPRCas9楼主2021/2/22 08:16
#include<iostream>
#include<algorithm>
#define N 1000010
using namespace std;
typedef long long LL;
LL school[N];
LL m, n, x;
LL ans = 0;
int main()
{
    cin >> m >> n;
    for(int i = 0; i < m; i++)
        cin >> school[i];
    sort(school, school + m);
    for(int i = 0; i < n; i++)
    {
        cin >> x;
        LL a = lower_bound(school, school + m, x) - school;
        //特判
        if(a == m)
            ans += x - school[m];
        else
        {
            if(a == 0)
                ans += school[0] - x;
            else
            {
                LL tmp_1 = school[a] - x;
                LL tmp_2 = x - school[a - 1];
                ans += min(tmp_1, tmp_2);
            }
        }
    }
    cout << ans;
    return 0;
}
2021/2/22 08:16
加载中...