A. Ehab Fails to Be Thanos

目录

1.Problem

2.Input

3.Output

4.Examples

4.1input

4.2output

5.Code

6.Conclusion


1.Problem

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?

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?

2.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.

3.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.

4.Examples

4.1input

3
1 2 2 1 3 1

4.2output

2 1 3 1 1 2

5.Code

#include<bits/stdc++.h>

#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
int a[2005];

int main(){
	n=readint();
	for(int i=1;i<=2*n;i++) a[i]=readint();
	sort(a+1,a+2*n+1);
	if(a[1]==a[2*n]) cout<<-1<<endl;
	else{
		for(int i=1;i<=2*n;i++) cout<<a[i]<<' ';
		cout<<endl;
	}
	return 0;
}

6.Conclusion

这段C++代码的主要目的是读取一个整数n,然后读取2n个整数,并对这2n个整数进行排序。最后,如果排序后的数组中的最小值和最大值相等,输出-1;否则,输出排序后的整数数组。

以下是代码的主要逻辑:

  1. 通过 readint 函数读取输入的整数 n

  2. 定义了一个整数数组 a,用于存储后续输入的2n个整数。

  3. 使用循环读取2n个整数,并将其存储在数组 a 中。

  4. 使用 sort 函数对数组 a 进行升序排序。

  5. 检查排序后的数组中的第一个元素和最后一个元素是否相等。如果相等,输出-1,表示无法满足要求。否则,输出排序后的整数数组。

总体来说,这段代码的功能是读取一系列整数,排序后检查是否有相同的最小和最大值,然后输出相应的结果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向阳而生__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值