A. Ehab Fails to Be Thanos

Links: https://codeforces.com/contest/1174/problem/A

Meaning of the questions:

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?

Ideas:

After ordering seeking first half and half and compared.

Code:

#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;
}

  

Guess you like

Origin www.cnblogs.com/YDDDD/p/10972855.html