码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 439D Devu and his Brother(排序)

时间:2014-06-16 19:22:38      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:style   class   code   http   tar   color   

题目链接:Codeforces 439D  Devu and his Brother


题目大意:Devu和他的哥哥互相深爱着对方,我确信他们是搞基的,为此我还去查了一下Devu是男人名还是女人名,但是后来发现His Brother,所以可以证明,他们就是搞基的。题目很简单,父亲给了他们两个人分别一个数组。但是Devu希望自己最小的数都可以不必哥哥最大的数小,现在对数组中的数有两种操作,一种是加1,一种是减1,问最少进行几次操作可以使得两个数组满足要求。


解题思路:将两个数组合并在一起,然后排序,第m个就是交界值。


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long ll;
const int N = 1e5+5;

int n, m;
ll a[N], b[N], c[N*2];

inline ll max(ll a, ll b) {
    return a > b ? a : b;
}

int main () {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        c[i] = a[i];
    }

    for (int i = 0; i < m; i++) {
        scanf("%lld", &b[i]);
        c[i+n] = b[i];
    }

    sort(c, c + n + m);

    ll tmp = c[m], ans = 0;

    for (int i = 0; i < n; i++)
        ans += max(0, tmp - a[i]);

    for (int i = 0; i < m; i++)
        ans += max(0, b[i] - tmp);

    printf("%lld\n", ans);
    return 0;
}

Codeforces 439D Devu and his Brother(排序),布布扣,bubuko.com

Codeforces 439D Devu and his Brother(排序)

标签:style   class   code   http   tar   color   

原文地址:http://blog.csdn.net/keshuai19940722/article/details/31076599

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!