CF1852B.Imbalanced Arrays
普及/提高-
通过率:0%
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.
输入格式
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 .
输出格式
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.
输入输出样例
输入#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] .