Codeforces Round #563 (Div. 2) A. Ehab Fails to Be Thanos(排序)

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

题意

有一大小为 $2n$ 的数组,能否重排元素使得前后一半和不同。

题解

从小到大排序即可,只要数组元素不单一就一定有解。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    n *= 2;
    int a[n] = {};
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    if (a[0] == a[n - 1])
        cout << -1 << "\n";
    else 
        for (int i = 0; i < n; i++)
            cout << a[i] << " ";
}

 

posted @ 2020-06-13 19:54  Kanoon  阅读(158)  评论(0)    收藏  举报