rankoo @ 2017-04-16 15:04:45
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int school[100100],student[100100],un[100100],m,n,total;
int score(int l,int r,int step)
{int x,c;
c=(l+r)/2;
if(school[c]>student[step]&&school[c-1]<student[step])
{x=abs(school[c]-student[step])<abs(school[c-1]-student[step])? abs(school[c]-student[step]):abs(school[c-1]-student[step]);
return x;
}
else
if(school[c+1]>student[step]&&school[c]<student[step])
{x=abs(school[c]-student[step])<abs(school[c+1]-student[step])? abs(school[c]-student[step]):abs(school[c+1]-student[step]);
return x;
}
else if(school[c]>student[step]&&school[c-1]>student[step]) score(l,c,step);
else score(c,r,step);
}
int main()
{cin>>m>>n;
for(int i=1;i<=m;++i) cin>>school[i];
for(int j=1;j<=n;++j) cin>>student[j];
sort(school+1,school+m+1);
for(int k=1;k<=n;++k)
total+=score(1,m,k);
cout<<total;
return 0;
}
by 牛寺另刂6 @ 2017-05-28 11:27:06
此帖已沉
by 子谦。 @ 2017-06-20 15:58:42
挖坟
欣赏大佬文笔
by Jummmmm @ 2017-10-02 13:44:24
真棒啊
by marshal王子祥 @ 2017-12-21 20:46:10
~~~欣赏大佬文笔~~~
by 新时代的黑客 @ 2018-08-10 11:50:13