liruizhou_lihui @ 2024-02-18 18:46:35
//#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
long long n,m,f[100000],x[100000];
long long ans;
int main()
{
cin>>m>>n;
for(int i=1;i<=m;i++)
{
cin>>f[i];
}
sort(f,f+m);
for(int i=1;i<=n;i++)
{
cin>>x[i];
}
for(int i=1;i<=n;i++)
{
long long mid,l=1,r=n;
while(l<=r)
{
mid=(l+r)/2;
if(f[mid]<x[i])l=mid+1;
if(f[mid]>x[i])r=mid-1;
}
if(x[i]<=f[1])
{
ans+=f[1]-x[i];
}
else
{
ans+=min(abs(f[l-1]-x[i]),abs(f[l]-x[i]));
}
}
cout<<ans;
return 0;
}
by propitious @ 2024-02-18 19:05:47
应该先判断学生是不是比最低录取线低或者比最高录取线高吧
by ruhemiaoshuyihan @ 2024-03-07 20:42:47
兄弟r应该等于m+1,我就是死在这里的