求助QAQ

P1678 烦恼的高考志愿

果圆 @ 2020-10-19 19:47:33

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int a[1000050],b[1000050],n,m,u;
int ttt(int x)
{
    int l=1,r=m;
    while(l<r)
    {
        int mid=l+r>>1;
        if(abs(a[mid]-x)<=abs(a[mid+1]-x)) r=mid;
        else l=mid+1;
    }
    return abs(a[l]-x);
}
int main()
{
    cin>>m>>n;
    for(int i=1;i<=m;i++)   cin>>a[i];
    for(int i=1;i<=n;i++)   cin>>b[i];
    sort(a+1,a+m+1);
    for(int i=1;i<=n;i++)   u+=ttt(b[i]);
    cout<<u;
    return 0;
}

by Remake_ @ 2020-10-19 19:50:40

用户名好评


by 果圆 @ 2020-10-19 22:11:01

@Miracle_Creator 我零分为什么啊?感觉没毛病


|