80分求助大佬!!!

P1678 烦恼的高考志愿

TaylorW @ 2021-10-18 10:40:43

#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int m,n;
long long int answer=0,lest=0x3f3f3f3f;
long long int school[1001000],student[1001000];
int main()
{
    //freopen("dream.in","r",stdin);
    //freopen("dream.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>m>>n;
    for (long long int i=1;i<=m;i++)
    {
        cin>>school[i];
    }
    sort(school+1,school+1+m);
    for (long long int i=1;i<=n;i++)
    {
        cin>>student[i];
    }
    for (long long int i=1;i<=n;i++)
    {
        if (student[i]<=school[1])
        {
            answer+=school[1]-student[i];
            continue;
        }
        if (student[i]>=school[m])
        {
            answer+=school[m]-student[i];
            continue;
        }
        long long int left=1,right=m,middle;
        while (left<right-1)
        {
            middle=(left+right)/2;
            if (school[middle]>student[i]) right=middle;
            else left=middle;
        }
        lest=min(student[i]-school[left],school[right]-student[i]);
        answer+=lest;
    }
    cout<<answer;
    //fclose(stdin);
    //fclose(stdout);
    return 0;

}

by 蓝翔之光森少 @ 2021-10-18 10:47:47

xd不行啊


by TaylorW @ 2021-10-18 10:49:00

@蓝翔之光森少

..................


by 周某无姓氏 @ 2021-10-18 10:58:49

xd不行啊


by 边铭烨 @ 2021-10-18 10:59:14

xd不行啊


by thatsgame @ 2021-10-18 10:59:37

xd不行啊


by l1247396180 @ 2021-10-18 11:00:35

xd不行啊


by 失败尽常态 @ 2021-10-18 11:00:37

xd不行啊


by Editzed @ 2021-10-18 11:01:00

xd不行啊


by Peur @ 2021-10-18 11:01:42

xd不行啊


by TaylorW @ 2021-10-18 11:02:03

xd不行啊


| 下一页