409397: GYM103496 J Joker
Description
Cindy thought a fine complement to her athletic prowess would be to learn more fine dexterity and sleight of hand, and what better way to do that than to learn some cool card tricks? The art of prestidigitation! Legerdemain!
Alice heard about this and excitedly wanted to teach Cindy a special card trick that she had learned. Well, it's actually not really a trick... it's more like a puzzle. A numbers puzzle. But Alice was really excited, so Cindy indulged her.
Cindy combined innumerably many decks, and dealt out $$$n$$$ cards face-up on the table. Each card is associated with some numerical value. Two through Ten are each worth the number on them. The "face cards" of Jack, Queen, and King each have a value of $$$10$$$. For this problem, the Ace always has a value of $$$1$$$. Finally, we have a special card, the Joker. The Joker can do anything! It can magically transform into any of the other card types.
Alice and Cindy view the face-up cards that were dealt. Some (possibly none) will be Jokers. Alice gives Cindy some target value $$$m$$$. Cindy must replace each Joker with a non-Joker card, such that the sum of the values of all face-up cards becomes exactly equal to $$$m$$$.
Cindy spent so much time practicing the shuffling and the dealing and the flourishes, that she doesn't have any energy left for the computations! Do you think you could help her out?
InputThe first line of input contains two space-separated integers $$$n$$$ and $$$m$$$, the number of face-up cards and the desired total value.
This is followed by a line containing a string with $$$n$$$ characters, encoding the face-up cards in the order they appear. Each character will be one of the following.
- A corresponds to an Ace.
- Digits 2 through 9 correspond to the numbers Two through Nine.
- T corresponds to a Ten.
- J, Q, K correspond to Jack, Queen, and King, respectively.
- * corresponds to a Joker.
If the task is possible, output a single line containing the word YES; otherwise, output NO.
If YES, output another line containing a string with $$$n$$$ characters. This should be exactly the same string given in the input, except each * has been replaced with one of A23456789TJQK, such that the total value of all the cards is exactly equal to $$$m$$$. If there are multiple solutions, output any of them.
Scoring$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 1 \leq n \leq 10^5 \\ 1 \leq m \leq 10^6 \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{30} & \text{There are no Jokers.} \\ \hline 2 & \mathbf{30} & \text{There is at most $1$ Joker.} \\ \hline 3 & \mathbf{20} & \text{There are at most $3$ Jokers.} \\ \hline 4 & \mathbf{20} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
5 26 2JAK3Output
YES 2JAK3Input
6 23 3A4A5*Output
YES 3A4A59Input
3 31 ***Output
NOInput
26 27 AAAAAAAAAAAAAAAAAAAAAAAAAAOutput
NO