计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle

#include<cstdio>
#include<algorithm>
using namespace std;
using namespace std; const int maxn=+;
int a[maxn],b[maxn]; int main()
{
int n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
for(int i=; i<=n; i++) scanf("%d",&a[i]);
for(int i=; i<=m; i++) scanf("%d",&b[i]);
sort(a+,a+n+);
sort(b+,b+m+);
b[]=-;
int now=m,ans=;
for(int i=n; i>=; i--)
{
while(abs(a[i]-b[now])>=abs(a[i]-b[now-])) now--;
ans=ans+abs(a[i]-b[now]);
}
printf("%d\n",ans);
}
return ;
}
上一篇:TinyMCE插件:RESPONSIVE filemanager 9 文件名统一格式化


下一篇:springboot学习随笔(二):简单的HelloWorld