A. Ehab Fails to Be Thanos

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

题目

You’re given an array a of length 2n. Is it possible to reorder it in such way so that the sum of the first n elements isn’t equal to the sum of the last n elements?

Input
The first line contains an integer n(1≤n≤1000), where 2n is the number of elements in the array a.
The second line contains 2n space-separated integers a1, a2, …, a2n (1≤ai≤106) — the elements of the array a

Output
If there’s no solution, print “-1” (without quotes). Otherwise, print a single line containing 2n
space-separated integers. They must form a reordering of a. You are allowed to not change the order

Example

input3

1 2 2 1 3 1

output

2 1 3 1 1 2

题意

给你一个长度为2n的数组a,对其重新排序,使得前n和后n元素的总和不想等,若无法排序输出-1,可以则输出重新排序过的长度为2n的数组a。

思路

先判断a数组中的数是否一样,若一样则无法排序使其前n个数之和不为后n个数之和,输出-1;

否则,求出前n与后n个数的和,判断他们是否相等,如果相等,将a排序再顺序输出即可,不想等则直接将原来a数组反向输出即可。

//
// Created by hjy on 19-6-4.
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+;
int main()
{
int n;
while(cin>>n)
{
int a[maxn];
int x;
cin>>x;
a[]=x;
int flag=a[];
int num=;
for(int i=;i<*n;i++)
{
cin>>a[i];
if(a[i]==flag)
num++;
}
if(num==*n)
cout<<"-1"<<endl;
else
{
int l=accumulate(a,a+n,);
cerr<<"l="<<l<<endl;//cerr对提交无影响 int r=accumulate(a+n,a+*n,);
cerr<<"r="<<r<<endl;
if(l!=r) {
for(int i=;i<*n;i++)
{
cout<<a[i]<<' ';
}
cout<<endl;
} else
{
sort(a,a+*n);
for(int i=;i<*n;i++)
cout<<a[i]<<' ';
cout<<endl;
} } }
return ;
}

Codeforces Round #563 (Div. 2)A的更多相关文章

  1. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  2. Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem

    链接:https://codeforces.com/contest/1174/problem/C 题意: You're given an integer nn. For every integer i ...

  3. Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person

    链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can ...

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

    链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it ...

  5. Codeforces Round #563 (Div. 2)C

    C. Ehab and a Special Coloring Problem 题目链接:http://codeforces.com/contest/1174/problem/C 题目 You're g ...

  6. Codeforces Round #563 (Div. 2)B

    B.Ehab Is an Odd Person 题目链接:http://codeforces.com/contest/1174/problem/B 题目 You’re given an array a ...

  7. Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem

    https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...

  8. Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale

    后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...

  9. Codeforces Round 563 (Div. 2) 题解

    自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则 ...

随机推荐

  1. 对于ado.net dataProvider的介绍

    学习刘皓的 ADO.NET入门教程(二)了解.NET数据提供程序 而来 这篇文章很一般,主要是对dataProvider做了个简单的介绍.因为在该系列文章中提到,ado.net主要有两部分 dataP ...

  2. 【翻译自mos文章】对于每个文件的 file.id and file.incarnation number,重命名文件别名

    对于每个文件的 file.id and file.incarnation number,重命名文件别名 參考原文: Rename Alias of Datafile as Per file.id an ...

  3. Blend_技巧篇_淡入淡出

    原文:Blend_技巧篇_淡入淡出 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010265681/article/details/766517 ...

  4. 熵、交叉熵、相对熵(KL 散度)意义及其关系

    熵:H(p)=−∑xp(x)logp(x) 交叉熵:H(p,q)=−∑xp(x)logq(x) 相对熵:KL(p∥q)=−∑xp(x)logq(x)p(x) 相对熵(relative entropy) ...

  5. ASP.NET Core 数据库上下文 - ASP.NET Core 基础教程 - 简单教程,简单编程

    原文:ASP.NET Core 数据库上下文 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 数据库上下文 上一章节中我们了解了 Entity Framewo ...

  6. 首个 C++ 编译器诞生 30 周年了,来听听 C++ 之父畅谈 C++

    原文  http://www.iteye.com/news/31076   C++ 之父 Bjarne Stroustrup 在 cfront 诞生 30 周年的访谈. 整整30年前,CFront 1 ...

  7. JS的innerText和innerHTML

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. 通通WPF随笔(2)——自己制作轻量级asp.net网站服务

    原文:通通WPF随笔(2)--自己制作轻量级asp.net网站服务 大学玩asp.net时就发现VS在Debug时会起一个web服务,这东西也太神奇了服务起得这么快,而相对于IIS又这么渺小. 前几个 ...

  9. C#基础加强篇—委托、Lambda表达式和事件(下)

    3.事件 事件作为C#中的一种类型,为类和类的实例定义发出通知的能力,从而将事件和可执行代码捆绑在了一起.事件是对象发送的消息,以发信号通知操作的发生.操作可能是由用户交互引起的,也可能是由某些其他的 ...

  10. QString转换为LPTSTR(使用了reinterpret_cast,真是叹为观止,但是也开阔了思路),三篇文章合起来的各种转换方法

    醉了,windows下宏定义了很多char类型 LPTSTR .今天,直接使用,qt报错,真TM费事. 将“CPU”转化为wcha_t * QString str = "CPU"; ...