#C5898. Taco Word Formation
Taco Word Formation
Taco Word Formation
You are given a word and a list of random strings. Your task is to determine whether the given word can be formed using the characters from the list of strings. Each string in the list can be used to contribute its characters, and characters are counted cumulatively. In other words, if the total frequency of every character in the provided strings (across all strings) is at least as high as its frequency in the word, then the answer is YES, otherwise it is NO.
More formally, let \( f_W(c) \) be the frequency of character \( c \) in the word, and \( f_S(c) \) be the total frequency of \( c \) in all the provided strings. The word can be formed if and only if:
[ \forall c, \quad f_W(c) \leq f_S(c). ]
Read the input from stdin
and print the result for each test case on a new line to stdout
.
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases. Each test case is described as follows:
- A line containing the word \(W\) that needs to be formed.
- A line containing an integer \(N\) representing the number of strings available.
- \(N\) subsequent lines, each containing one string.
Note: The strings may be empty.
outputFormat
For each test case, output a single line containing either YES
if the word can be formed or NO
otherwise.
3
apple
3
ap
p
ple
banana
2
an
ban
hello
2
hel
lo
YES
NO
YES
</p>