#P10317. [SHUPC 2024] 小A的皇室战争卡组

[SHUPC 2024] 小A的皇室战争卡组

Problem Description

Xiao A really likes playing the game Clash Royale. There are 33 types of cards in Clash Royale: troops, buildings, and spells. A deck carries 88 cards. A valid deck contains 010 \sim 1 building cards, 131 \sim 3 spell cards, and there is no restriction on troop cards. Each card has its own level aia_i and type cic_i.

Now Xiao A wants to have a friendly battle with Xiao B, so he needs to build a battle deck. Xiao A has nn 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-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 (T103)T\ (T \le 10^3), indicating the number of test cases.

For each test case, the first line contains a positive integer n (8n105)n\ (8 \le n \le 10^5), representing the total number of cards Xiao A has. It is guaranteed that n105\sum n \le 10^5.

The second line of each test case contains nn positive integers, representing the type of each card ci (1ci3)c_i\ (1 \le c_i \le 3). Type 11 represents a troop card, type 22 represents a building card, and type 33 represents a spell card.

The third line of each test case contains nn positive integers, representing the level of each card ai (1ai15)a_i\ (1 \le a_i \le 15).

The fourth line of each test case contains 88 positive integers, representing the level of each of Xiao B's cards xi (1xi15)x_i\ (1 \le x_i \le 15).

Output Format

Output TT lines, each containing a string. If Xiao A can win, output Yes; otherwise output No.

3
10
2 3 3 3 1 1 1 1 1 1 
7 8 9 1 2 3 4 5 6 6
13 13 13 13 3 3 3 3
10
2 2 3 1 1 1 1 1 1 1
10 9 2 2 2 2 2 2 2 2
5 5 5 5 5 5 5 6
8
1 1 1 1 1 1 1 1
15 15 15 15 15 15 15 15
1 1 1 1 1 1 1 1
Yes
No
No

Hint

Sample explanation:

In the first sample, Xiao A can choose cards 1,2,3,6,7,8,9,101, 2, 3, 6, 7, 8, 9, 10. The average level of the battle deck is 66, while the average level of Xiao B's battle deck is 88. Since XiaoAXiaoA's average level \ge XiaoB's average level 2-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