1413D.md (2827B)
1 Source: https://codeforces.com/problemset/problem/1413/D 2 3 D. Shurikens 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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. 22 23 Tenten keeps a record for all events, and she ends up with a list of the following types of records: 24 25 * + means that she placed another shuriken on the showcase; 26 * - x means that the shuriken of price $x$ was bought. 27 28 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! 29 30 Input 31 32 The first line contains the only integer $n$ ($1\leq n\leq 10^5$) standing for the number of shurikens. 33 34 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. 35 36 Output 37 38 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". 39 40 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. 41 42 Examples 43 44 Input 45 46 ``` 47 4 48 + 49 + 50 - 2 51 + 52 - 3 53 + 54 - 1 55 - 4 56 ``` 57 58 Output 59 60 ``` 61 YES 62 4 2 3 1 63 ``` 64 65 Input 66 67 ``` 68 1 69 - 1 70 + 71 ``` 72 73 Output 74 75 ``` 76 NO 77 ``` 78 79 Input 80 81 ``` 82 3 83 + 84 + 85 + 86 - 2 87 - 1 88 - 3 89 ``` 90 91 Output 92 93 ``` 94 NO 95 ``` 96 97 Note 98 99 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. 100 101 In the second example the first customer bought a shuriken before anything was placed, which is clearly impossible. 102 103 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.