time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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?
Input
The first line contains an integer nn (1≤n≤10001≤n≤1000), where 2n2n is the number of elements in the array aa.
The second line contains 2n2n space-separated integers a1a1, a2a2, ……, a2na2n (1≤ai≤1061≤ai≤106) — the elements of the array aa.
Output
If there's no solution, print "-1" (without quotes). Otherwise, print a single line containing 2n2n space-separated integers. They must form a reordering of aa. You are allowed to not change the order.
Examples
input
Copy
3 1 2 2 1 3 1
output
Copy
2 1 3 1 1 2
input
Copy
1 1 1
output
Copy
-1
Note
In the first example, the first nn elements have sum 2+1+3=62+1+3=6 while the last nn elements have sum 1+1+2=41+1+2=4. The sums aren't equal.
In the second example, there's no solution.
解题说明:水题,先排序,判断数字是否相同,相同输出-1,否则从小到大输出即可。
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
int arr[2002];
for (int i = 0; i < 2 * n; i++)
{
cin >> arr[i];
}
sort(arr, arr + 2 * n);
if (arr[0] == arr[2 * n - 1])
{
cout << -1 << endl;
}
else
{
for (int i = 0; i<2 * n; i++)
{
cout << arr[i] << " ";
}
}
return 0;
}