A13677 | Shurikens
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 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!
输入格式
The first line contains the only integer $n$ ( $1\leq n\leq 10^5$ ) 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.
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.
输出格式
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.
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.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted