luogu#P6956. [NEERC2017] Easy Quest

[NEERC2017] Easy Quest

题目描述

A young hero is starting his heroic life. The wise wizard suggested him an easy first quest. During this quest our young hero meets nn magical creatures, in specific order. In order to help the young hero, the wizard gave him a clue -- a list of nn integers ai.a_{i}.

If aia_{i} is positive, then the i-th magical creature is benevolent and gives to our hero one magical item of type ai.a_{i}. The hero can keep several items of the same type.

If aia_i is negative, then the i-th magical creature is evil and in order to defeat it the young hero needs one magical item of type ai.−a_{i}. All magical items are fragile and can be used only once.

If aia_{i} is zero, then the i-th creature is a unicorn. It gives the hero any magical item he asks for, but only one.

Your task is to help the young hero to finish the first quest, defeating all enemies on the way, or say that it is impossible.

输入格式

The first line of input contains one integer n(1n1000)n (1 \le n \le 1000) . The second line contains nn integers ai(1000ai1000)a_{i} (−1000 \le a_{i} \le 1000) .

输出格式

If it is impossible to defeat all enemies, then output one string No. If it is possible, then output string Yes, and in the next line output the types of items the hero should ask the unicorns for, in order they meet during the quest. Types must be integers in range from 11 to 10001000 inclusive. If there are several solutions, output any of them.

题目大意

一个英雄进行了一次探索。在这次探索中,英雄按特定顺序遇到了 nn 个魔法生物,第 ii 个魔法生物对应 aia_i

aia_i 为正数时,第 ii 个魔法生物会给英雄提供一个为 aia_i 的魔法物品。

aia_i 为负数时,第 ii 个魔法生物需要英雄消耗一个为 ai-a_i 的魔法物品。

aia_i00 时,第 ii 个魔法生物可以给英雄提供一个任意的魔法物品。

你需要回答英雄是否可以完成这次探索(经过所有魔法生物),如果可以,请回答 aia_i00 魔法生物应该为英雄提供哪种魔法物品。

10
1 0 -4 0 0 -1 -3 0 -1 -2

Yes
4 1 3 2

5
5 8 0 -6 -3

No

3
2 -2 -2

No

提示

Time limit: 3 s, Memory limit: 512 MB.

spj provider:

/user/137367