首页 > 其他 > 详细

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

时间:2015-12-27 19:08:05      阅读:196      评论:0      收藏:0      [点我收藏+]
#include<cstdio>
#include<algorithm>
using namespace std;
using namespace std;

const int maxn=100000+10;
int a[maxn],b[maxn];

int main()
{
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        for(int i=1; i<=n; i++) scanf("%d",&a[i]);
        for(int i=1; i<=m; i++) scanf("%d",&b[i]);
        sort(a+1,a+n+1);
        sort(b+1,b+m+1);
        b[0]=-9999999;
        int now=m,ans=0;
        for(int i=n; i>=1; i--)
        {
            while(abs(a[i]-b[now])>=abs(a[i]-b[now-1])) now--;
            ans=ans+abs(a[i]-b[now]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

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

原文:http://www.cnblogs.com/zufezzt/p/5080470.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!