CF297C.Splitting the Uniqueness

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polar bears like unique arrays — that is, arrays without repeated elements.

You have got a unique array s with length n containing non-negative integers. Since you are good friends with Alice and Bob, you decide to split the array in two. Precisely, you need to construct two arrays a and b that are also of length n, with the following conditions for all i (1 ≤ i ≤ n):

  • a__i, b__i are non-negative integers;
  • s__i = a__i + b__i .

Ideally, a and b should also be unique arrays. However, life in the Arctic is hard and this is not always possible. Fortunately, Alice and Bob are still happy if their arrays are almost unique. We define an array of length n to be almost unique, if and only if it can be turned into a unique array by removing no more than entries.

For example, the array [1, 2, 1, 3, 2] is almost unique because after removing the first two entries, it becomes [1, 3, 2]. The array [1, 2, 1, 3, 1, 2] is not almost unique because we need to remove at least 3 entries to turn it into a unique array.

So, your task is to split the given unique array s into two almost unique arrays a and b.

北极熊喜欢“独特”的数组——即不含重复元素的数组。

你得到了一个长度为 nn 的独特数组 ss,其中包含非负整数。由于你与爱丽丝(Alice)和鲍勃(Bob)是好朋友,你决定将该数组拆分为两个数组。具体而言,你需要构造两个同样长度为 nn 的数组 aa 和 bb,使得对所有 ii(1≤i≤n1 \le i \le n)均满足以下条件:

  • aia_i、bib_i 均为非负整数;
  • si=ai+bis_i = a_i + b_i。

理想情况下,aa 和 bb 本身也应为独特数组。然而,北极的生活十分艰难,这并不总能实现。幸运的是,只要爱丽丝和鲍勃的数组是“几乎独特”的,他们依然会感到开心。我们定义:一个长度为 nn 的数组是几乎独特的,当且仅当它可以通过删除至多 个元素而变为一个独特数组。

例如,数组 [1, 2, 1, 3, 2][1,\,2,\,1,\,3,\,2] 是几乎独特的,因为删去前两个元素后,它变为 [1, 3, 2][1,\,3,\,2]。而数组 [1, 2, 1, 3, 1, 2][1,\,2,\,1,\,3,\,1,\,2] 则不是几乎独特的,因为至少需要删除 3 个元素才能使其变为独特数组。

因此,你的任务是将给定的独特数组 ss 拆分为两个几乎独特的数组 aa 和 bb。

输入格式

The first line of the input contains integer n (1 ≤ n ≤ 105).

The second line contains n distinct integers _s_1, _s_2, ... s__n (0 ≤ s__i ≤ 109).

输入的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)。

第二行包含 nn 个互不相同的整数 s1,s2,…,sns_1, s_2, \dots, s_n(0≤si≤1090 \leq s_i \leq 10^9)。

输出格式

If it is possible to make Alice and Bob happy (if you can split the given array), print "YES" (without quotes) in the first line. In the second line, print the array a. In the third line, print the array b. There may be more than one solution. Any of them will be accepted.

If it is impossible to split s into almost unique arrays a and b, print "NO" (without quotes) in the first line.

如果可以使得 Alice 和 Bob 都开心(即可以将给定数组进行划分),则在第一行输出 "YES"(不带引号)。
在第二行输出数组 a。
在第三行输出数组 b。
可能存在多种解法,任意一种均可接受。

如果无法将 s 划分为两个几乎唯一的数组 a 和 b,则在第一行输出 "NO"(不带引号)。

输入输出样例

  • 输入#1

    6
    12 5 8 3 11 9

    输出#1

    YES
    6 2 6 0 2 4
    6 3 2 3 9 5

说明/提示

In the sample, we can remove the first two entries from a and the second entry from b to make them both unique.

在样例中,我们可以从 a 中删除前两个元素,从 b 中删除第二个元素,从而使两者均变为无重复元素的序列。

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

首页