A. Ehab Fails to Be Thanos

时间:2019-06-04 13:44:55   收藏:0   阅读:249

链接:https://codeforces.com/contest/1174/problem/A

题意:

You‘re given an array aa of length 2n2n. Is it possible to reorder it in such way so that the sum of the first nn elements isn‘t equal to the sum of the last nn elements?

思路:

排序后求前一半和后一半的和比较。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;

int a[2010];

int main()
{
    cin >> n;
    for (int i = 1;i <= 2*n;i++)
        cin >> a[i];
    sort(a+1, a+1+2*n);
    if (accumulate(a+1, a+1+n, 0) == accumulate(a+n+1, a+1+2*n, 0))
        cout << -1 << endl;
    else
    {
        for (int i = 1; i <= 2 * n; i++)
            cout << a[i] << ‘ ‘;
        cout << endl;
    }

    return 0;
}

  

原文:https://www.cnblogs.com/YDDDD/p/10972855.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!