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 lamp_forever @ 2021-10-18 11:22:49
xd不行啊
by weiliyu @ 2021-10-18 11:26:50
xd不行啊
by Buried_Dream @ 2021-10-18 11:38:03
xd不行啊
by gg167868 @ 2021-10-18 18:16:18
xd不行啊