No.1017 Reiwa Sequence
Problem Statement
There is a sequence $A = A_1,A_2,\ldots,A_N$ of length $N$ consisting of positive integers. You will construct a sequence $B = B_1,B_2,\ldots,B_N$ by performing the following operation for each $i\in\{1,2,\ldots,N\}$.
- Choose $x_i\in \{-1,0,1\}$ and set $B_i = A_ix_i$.
Make sure that both of the following $2$ conditions hold.
- The sequence $B$ is zero-sum. That is, $\sum_{i=1}^NB_i=0$ holds.
- The sequence $B$ has a term that is not $0$.
Input
$N$ $A_1\ A_2\ \cdots\ A_N$
- All input values are integers.
- $1\leqq N\leqq 150000$
- $1\leqq A_i\leqq 150000$
Output
If it is impossible to obtain a sequence satisfying the conditions through the operations, print No.
If it is possible, print Yes on the $1$st line, and print the resulting sequence $B = B_1,B_2,\ldots,B_N$ separated by spaces on the $2$nd line.
Print a newline at the end.
Sample
Sample 1
Input
5 1 2 3 4 5
Output
Yes 1 -2 0 -4 5
Other sequences such as 0 -2 3 4 -5 and 0 2 3 0 -5 can also be obtained.
Any sequence satisfying the conditions will be judged as correct.
Note that 0 0 0 0 0 does not satisfy the conditions.
Sample 2
Input
3 2019 5 1
Output
No
Sample 3
Input
2 10 10
Output
Yes 10 -10
Sample 4
Input
9 314 159 265 358 979 323 846 264 338
Output
Yes 314 159 0 358 0 -323 -846 0 338
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
maspy
beet