其他分享
首页 > 其他分享> > A. Ehab Fails to Be Thanos

A. Ehab Fails to Be Thanos

作者:互联网

链接: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;
}

  

标签:Fails,elements,const,nn,int,sum,long,Thanos,Ehab
来源: https://www.cnblogs.com/YDDDD/p/10972855.html