首页 > 其他 > 详细

codeforces 439D Devu and Partitioning of the Array(有深度的模拟)

时间:2014-08-04 21:09:07      阅读:307      评论:0      收藏:0      [点我收藏+]

题目

 

//参考了网上的代码

 

注意答案可能超过32位

 

bubuko.com,布布扣
//要达成目标,就是要所有数列a的都比数列b的要小或者等于
//然后,要使最小的要和最大的一样大,就要移动(大-小)步,
//要使较小的要和较大的一样大,也是要移动(较大-较小)步
//然后都加在一起就好了

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long 
int cmp(ll x,ll y)
{
    return x>y;
}
ll a[100010],b[100010];
int main()
{
    ll n,m;
    cin >> n>> m;
    for(int i=0;i<n;i++)
        cin >> a[i];
    for(int i=0;i<m;i++)
        cin >> b[i];
    sort(a,a+n);
    sort(b,b+m,cmp);
    if(n>m)n=m;
    ll ans=0;
    for(int i=0;i<n;i++)
        if(a[i]<b[i])
            ans+=(b[i]-a[i]);
    cout << ans <<endl;
    return 0;
}
View Code

 

codeforces 439D Devu and Partitioning of the Array(有深度的模拟),布布扣,bubuko.com

codeforces 439D Devu and Partitioning of the Array(有深度的模拟)

原文:http://www.cnblogs.com/laiba2004/p/3890808.html

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