CF891B.Gluttony

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {_x_1, _x_2, ..., x__k} (1 ≤ x__i ≤ n, 0 < k < n) the sums of elements on that positions in a and b are different, i. e.

给你一个包含 $ n $ 个互不相同整数的数组 $ a $。请通过对 $ a $ 进行重排构造数组 $ b $,使得对任意非空索引子集 $ S = {x_1, x_2, \dots, x_k} $(其中 $ 1 \le x_i \le n $,且 $ 0 < k < n $),数组 $ a $ 和 $ b $ 在这些位置上的元素之和均不相等,即

输入格式

The first line contains one integer n (1 ≤ n ≤ 22) — the size of the array.

The second line contains n space-separated distinct integers _a_1, _a_2, ..., a__n (0 ≤ a__i ≤ 109) — the elements of the array.

第一行包含一个整数 nn(1≤n≤221 \leq n \leq 22)—— 数组的大小。

第二行包含 nn 个以空格分隔的互不相同的整数 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n(0≤ai≤1090 \leq a_i \leq 10^9)—— 数组的元素。

输出格式

If there is no such array b, print -1.

Otherwise in the only line print n space-separated integers _b_1, _b_2, ..., b__n. Note that b must be a permutation of a.

If there are multiple answers, print any of them.

如果不存在这样的数组 bb,则输出 −1-1。

否则,在唯一的一行中输出 nn 个用空格分隔的整数 b1, b2, …, bnb_1,\ b_2,\ \dots,\ b_n。注意:bb 必须是 aa 的一个排列。

如果存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    1 2

    输出#1

    2 1
  • 输入#2

    4
    1000 100 10 1

    输出#2

    100 1 1000 10

说明/提示

An array x is a permutation of y, if we can shuffle elements of y such that it will coincide with x.

Note that the empty subset and the subset containing all indices are not counted.

数组 xx 是 yy 的一个排列,当且仅当我们能够重排 yy 的元素,使其与 xx 完全一致。

注意:空子集以及包含所有下标的子集均不计入。

输入解题思路,AI测评打分。不知道怎么写?

首页