P10317 [SHUPC 2024] Xiao A's Clash Royale Deck
Description
Xiao A really likes playing the game Clash Royale. There are $3$ types of cards in Clash Royale: troops, buildings, and spells. A deck carries $8$ cards. A valid deck contains $0 \sim 1$ building cards, $1 \sim 3$ spell cards, and there is no restriction on troop cards. Each card has its own level $a_i$ and type $c_i$.
Now Xiao A wants to have a friendly battle with Xiao B, so he needs to build a battle deck. Xiao A has $n$ cards in total. The type and level of each card are known, and the level of each battle card of Xiao B is known. Since Xiao A is very confident in his skill, as long as **the average level of his battle cards $\ge$ the average level of the opponent's battle cards $-2$**, **and the deck is a valid deck**, he can guarantee victory.
Now please help Xiao A think about it: can he guarantee victory?
Input Format
The first line contains an integer $T\ (T \le 10^3)$, indicating the number of test cases.
For each test case, the first line contains a positive integer $n\ (8 \le n \le 10^5)$, representing the total number of cards Xiao A has. It is guaranteed that $\sum n \le 10^5$.
The second line of each test case contains $n$ positive integers, representing the type of each card $c_i\ (1 \le c_i \le 3)$. Type $1$ represents a troop card, type $2$ represents a building card, and type $3$ represents a spell card.
The third line of each test case contains $n$ positive integers, representing the level of each card $a_i\ (1 \le a_i \le 15)$.
The fourth line of each test case contains $8$ positive integers, representing the level of each of Xiao B's cards $x_i\ (1 \le x_i \le 15)$.
Output Format
Output $T$ lines, each containing a string. If Xiao A can win, output `Yes`; otherwise output `No`.
Explanation/Hint
Sample explanation:
In the first sample, Xiao A can choose cards $1, 2, 3, 6, 7, 8, 9, 10$. The average level of the battle deck is $6$, while the average level of Xiao B's battle deck is $8$. Since $XiaoA$'s average level $\ge$ XiaoB's average level $-2$, Xiao A can guarantee victory.
In the second sample, no matter how Xiao A configures the deck, he cannot make the average level satisfy the condition, so he cannot win.
In the third sample, Xiao A cannot configure a valid deck, so he cannot win either.
Translated by ChatGPT 5