CF1413D.Shurikens
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Tenten runs a weapon shop for ninjas. Today she is willing to sell n shurikens which cost 1, 2, ..., n ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is fairly simple: sometimes Tenten places another shuriken (from the available shurikens) on the showcase, and sometimes a ninja comes in and buys a shuriken from the showcase. Since ninjas are thrifty, they always buy the cheapest shuriken from the showcase.
Tenten keeps a record for all events, and she ends up with a list of the following types of records:
-
- means that she placed another shuriken on the showcase;
- - x means that the shuriken of price x was bought.
Today was a lucky day, and all shurikens were bought. Now Tenten wonders if her list is consistent, and what could be a possible order of placing the shurikens on the showcase. Help her to find this out!
Tenten 经营一家面向忍者的武器商店。今天,她准备出售 n 枚手里剑,价格分别为 1、2、…、n 两(当地货币)。在一天中,Tenten 会将手里剑依次摆放到展柜上,而展柜在每天开始时是空的。她的工作非常简单:有时她会从剩余未售出的手里剑中再取一枚摆放到展柜上;有时则会有忍者进店,从展柜上买走一枚手里剑。由于忍者十分节俭,他们总是购买展柜上最便宜的那枚手里剑。
Tenten 会记录下当天发生的所有事件,最终得到一份包含如下两类记录的列表:
+表示她向展柜上新增了一枚手里剑;- x表示价格为 x 的手里剑被买走了。
今天是个幸运日,所有 n 枚手里剑全部售罄。现在 Tenten 想知道,她所记录的这份列表是否自洽?如果自洽,又是否存在一种可能的手里剑上架顺序?请帮她解决这个问题!
输入格式
The first line contains the only integer n (1≤n≤105) standing for the number of shurikens.
The following 2n lines describe the events in the format described above. It's guaranteed that there are exactly n events of the first type, and each price from 1 to n occurs exactly once in the events of the second type.
第一行包含唯一一个整数 n(1≤n≤105),表示手里剑的数量。
接下来的 2n 行按上述格式描述事件。保证其中恰好有 n 个第一类事件,且第二类事件中每个价格 1 到 n 恰好各出现一次。
输出格式
If the list is consistent, print "YES". Otherwise (that is, if the list is contradictory and there is no valid order of shurikens placement), print "NO".
In the first case the second line must contain n space-separated integers denoting the prices of shurikens in order they were placed. If there are multiple answers, print any.
如果该列表是一致的,则输出 "YES"。否则(即该列表是矛盾的,不存在有效的手里剑放置顺序),输出 "NO"。
在第一种情况下,第二行必须包含 n 个用空格分隔的整数,表示手里剑按其放置顺序对应的价格。如果有多个答案,输出任意一个即可。
输入输出样例
输入#1
4 + + - 2 + - 3 + - 1 - 4
输出#1
YES 4 2 3 1
输入#2
1 - 1 +
输出#2
NO
输入#3
3 + + + - 2 - 1 - 3
输出#3
NO
说明/提示
In the first example Tenten first placed shurikens with prices 4 and 2. After this a customer came in and bought the cheapest shuriken which costed 2. Next, Tenten added a shuriken with price 3 on the showcase to the already placed 4-ryo. Then a new customer bought this 3-ryo shuriken. After this she added a 1-ryo shuriken. Finally, the last two customers bought shurikens 1 and 4, respectively. Note that the order [2,4,3,1] is also valid.
In the second example the first customer bought a shuriken before anything was placed, which is clearly impossible.
In the third example Tenten put all her shurikens onto the showcase, after which a customer came in and bought a shuriken with price 2. This is impossible since the shuriken was not the cheapest, we know that the 1-ryo shuriken was also there.
在第一个例子中,天天首先放置了价格为 4 和 2 的手里剑。随后,一名顾客进店并买走了最便宜的那把手里剑(价格为 2)。接着,天天在已放置的 4-ryo 手里剑基础上,又将一把价格为 3 的手里剑摆上展台。然后,下一位顾客买走了这把 3-ryo 的手里剑。此后,她又添加了一把 1-ryo 的手里剑。最后,最后两位顾客分别买走了价格为 1 和 4 的手里剑。注意,顺序 [2,4,3,1] 同样是合法的。
在第二个例子中,第一位顾客在任何手里剑被放置之前就购买了一把,这显然不可能。
在第三个例子中,天天先将她所有的手里剑全部摆上了展台,之后一名顾客进店并买走了一把价格为 2 的手里剑。这是不可能的,因为该手里剑并非最便宜的——我们知道当时展台上还有一把 1-ryo 的手里剑。
输入解题思路,AI测评打分。不知道怎么写?