CF1852B.Imbalanced Arrays
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ntarsis has come up with an array a of n non-negative integers.
Call an array b of n integers imbalanced if it satisfies the following:
- −n≤bi≤n, bi=0,
- there are no two indices (i,j) (1≤i,j≤n) such that bi+bj=0,
- for each 1≤i≤n, there are exactly ai indices j (1≤j≤n) such that bi+bj>0, where i and j are not necessarily distinct.
Given the array a, Ntarsis wants you to construct some imbalanced array. Help him solve this task, or determine it is impossible.
Ntarsis 构造了一个由 n 个非负整数组成的数组 a。
称一个由 n 个整数组成的数组 b 是失衡的(imbalanced),当且仅当它满足以下条件:
- 对每个 i,有 −n≤bi≤n,且 bi=0;
- 不存在任意两个下标 (i,j)(其中 1≤i,j≤n),使得 bi+bj=0;
- 对每个 1≤i≤n,恰好存在 ai 个下标 j(其中 1≤j≤n),使得 bi+bj>0(注意:此处 i 与 j 可以相同)。
给定数组 a,Ntarsis 希望你构造出一个失衡数组 b;若无法构造,请判断该任务不可能完成。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105). The description of the test cases follows.
The first line of each test case has a single integer n (1≤n≤105).
The next line contains n integers a1,a2,…,an (0≤ai≤n).
It is guaranteed that the sum of n across all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤105)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105)。
下一行包含 n 个整数 a1,a2,…,an(0≤ai≤n)。
保证所有测试用例的 n 值之和不超过 105。
输出格式
For each test case, output "NO" if there exists no imbalanced array.
Otherwise, output "YES". Then, on the next line, output n integers b1,b2,…,bn where bi=0 for all 1≤i≤n — an imbalanced array.
对于每个测试用例,若不存在不平衡数组,则输出 “NO”。
否则,输出 “YES”。然后在下一行输出 n 个整数 b1,b2,…,bn,其中对所有 1≤i≤n 均满足 bi=0 —— 即一个不平衡数组。
输入输出样例
输入#1
5 1 1 4 1 4 3 4 3 0 1 0 4 4 3 2 1 3 1 3 1
输出#1
YES 1 NO YES -3 1 -2 YES 4 2 -1 -3 YES -1 3 -1
说明/提示
For the first test case, b=[1] is an imbalanced array. This is because for i=1, there is exactly one j (j=1) where b1+bj>0.
For the second test case, it can be shown that there exists no imbalanced array.
For the third test case, a=[0,1,0]. The array b=[−3,1,−2] is an imbalanced array.
- For i=1 and i=3, there exists no index j such that bi+bj>0.
- For i=2, there is only one index j=2 such that bi+bj>0 (b2+b2=1+1=2).
Another possible output for the third test case could be b=[−2,1,−3].
对于第一个测试用例,b=[1] 是一个不平衡数组。这是因为当 i=1 时,恰好存在一个 j(即 j=1),使得 b1+bj>0。
对于第二个测试用例,可以证明不存在不平衡数组。
对于第三个测试用例,a=[0,1,0]。数组 b=[−3,1,−2] 是一个不平衡数组。
- 当 i=1 和 i=3 时,不存在任何下标 j,使得 bi+bj>0。
- 当 i=2 时,仅存在一个下标 j=2,使得 bi+bj>0(即 b2+b2=1+1=2)。
第三个测试用例的另一个可能输出是 b=[−2,1,−3]。
输入解题思路,AI测评打分。不知道怎么写?