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. 简单推导 PCA

    考虑二维数据降低到一维的例子,如下图所示: 最小化投影方差(maximize projected variance): 1N∑n=1N(uuT1xn−uuT1x¯)=uuT1Suu1,s.t.uuT1 ...

  2. Win10局域网内无法共享的解决方法分享(开启Server和ComputerBrowser服务,其它文章也不错)

    局域网共享是办公环境下经常使用的,而有些用户反应在升级到win10系统后,网络总是无法共享,给用户带来了很大的困扰,如果你也遇上这样的情况,并通过一些方法无较后,不妨尝试下小编提供的方法. 如果在Wi ...

  3. 使用 LaTex 制作个人简历(CV,英文版)

    \documentclass[12pt]{article} \textwidth=6.5in \textheight=9in \topmargin=-1.1in \headheight=0in \he ...

  4. Chart.js报告

    引进需要Chart.js <%@ page language="java" pageEncoding="UTF-8"%> <!DOCTYPE ...

  5. MySQL更改表的存储引擎

    MySQL它提供了多种数据库存储引擎,存储引擎负责MySQL存储和检索数据的数据库.不同的存储引擎具有不同的特性,能须要将一个已经存在的表的存储引擎转换成另外的一个存储引擎.有非常多方法能够完毕这样的 ...

  6. Webx框架:Pipeline基本介绍

    Pipeline. 它是管道的含义.一个管道阀门可以安装非常多.有许多可能的分支.它是用来控制页处理.它需要在被定义pipeline.xml文件.该文件是为每个阀的标签.该文件可以放一些简单的控制语句 ...

  7. Raw-OS备用事件源代码分析

    作为分析的内核版本2014-04-15,基于1.05正式版,blogs我们会跟上的内核开发进度的最新版本,如果出现源代码的目光"???"的话.没有深究的部分是理解. Raw-OS官 ...

  8. c# 自定义公共类CallFunction-调用函数信息帮助类

    /// <summary> /// 调用函数信息 /// </summary> public class CallFunction { /// <summary> ...

  9. aspx页面@Page指令解析

    @Page指令位于每个ASP.NET页面的顶部,告诉ASP.NET这个具体页面使用什么属性,以及该页面继承的用户控件.ASP.NET页面@Page指令属性有:AspCompat.Async.Async ...

  10. Delphi XE5 Android Dialogs 对话框(模拟做了一套)

    最近要在Android中使用对话框, 但发现无现成的, TOpenDialog等已经不支持移动设备,还好系统提供了一些文件目录函数可用,于是简单的模拟了一个,支持OpenDialog ,SaveDia ...