Problem B. AraBellaC

时间限制 1000 ms   内存限制 64 MB

Princess Arabella loves the letter `C`, which earned her the epithet `ArraBellaC`. She would like to endeavor to construct a periodic string with length $n(n \leq 20000)$ to spare her tedious time. In every period of the string, the substring begins with dozens of `A`s and ends with dozens of `C`s, and dozens of `B`s are inserted between them, and the number of `A`, `B`, `C` is $a$, $b$, $c$.(For example, if $a=1$, $b=1$, $c=2$ then one of the period of the string is `ABCC`, and the periodic string is `ABCCABCC……`).Note that in the last period of the string, the substring can be incomplete and the last few letters of the period can be cut down.

And now, Arabella has constructed a periodic string, she want to give you a question: if she tells you the character is $C_i(C_i \in \{A, B, C\})$ in the $X_i(X_i \leq 10000)$ , then could you tell her the value of $a,b,c$? If there are multiple answers, please find the lexicographically smallest answer. If you can’t find a valid answer, please print `NO`
 

输入数据

The first line gives an integer $T(1\leq T \leq 40)$ , which indicates the number of cases in the input.$\\$
The first line of every case contains only one integer $m(1 \leq m \leq 5000)$, which means the number of characters AraBella told you.$\\$
A number $X_i(1\leq X_i\leq 10000)$ and a letter $C_i$ are given in the following m lines, which means the position $X_i$ in the string with letter $C_i$.
 

输出数据

Print $a, b, c$ in order. If there are multiple answers, please find the lexicographically smallest answer. If you can’t find a valid answer, please print `NO`.(It is gratuated that $0 < a, b, c$, and please forget my poor Yinglish)
 

样例输入

复制
2
3
1 A
2 B
3 C
4
1 A
2 C
3 B
4 C

样例输出

复制
1 1 1
NO

提交

请先 登录

© 2025 FAQs Contact About