Dear problem setter, I downloaded Hearthstone. Why is my Threads of Despair a three-cost card?
—Pan-fried-chicken
Problem Statement
Fried-chicken is a devoted player of Hearthstone. Since the game resumed operations in the Chinese mainland, he has been obsessed with it and reached Silver 2 rank in Standard mode. Today, while ranking up using Death Knight, he encountered a formidable opponent, Stewed-chicken, and was left with just $1$ Health. To survive, Fried-chicken must eliminate all of Stewed-chicken’s minions. Fortunately, he can use spell cards and his minions’ attacks to achieve this goal.
Specifically, this game involves two factions: Fried-chicken and Stewed-chicken. Each faction has some minions. The $i$-th minion has $h_i$ Health. It is now Fried-chicken’s turn, and each of his minions can attack any one minion from the opposing faction at most once. When one minion attacks another, both minions lose $1$ Health. If a minion’s Health is reduced to $0$ or less, it dies and can no longer attack or be attacked.
To achieve his goal, Fried-chicken casts the spell “Threads of Despair,” causing every minion to explode upon death, which reduces the Health of all minions by $1$. If the explosion causes the death of other minions, other minions will also explode immediately. Fried-chicken cannot have his minions attack other minions until all explosion effects have finished. After casting the spell, Fried-chicken can make his minions attack Stewed-chicken’s minions in any order he chooses. He wants to know if there exists an attack order that allows Fried-chicken to eliminate all of Stewed-chicken’s minions.
Input
Each test file contains multiple test cases. The first line contains the number of test cases $T$ ($1 \leq T \leq 5 \times 10^5$). The description of the test cases follows.
The first line of each test case contains two integers $n$ and $m$ ($1 \leq n, m \leq 5 \times 10^5$), representing the number of Fried-chicken’s minions and Stewed-chicken’s minions, respectively.
The second line contains $n$ integers $h_1, h_2, \dots, h_n$ ($1 \leq h_i \leq 10^9$), where $h_i$ represents the Health of Fried-chicken’s $i$-th minion.
The third line contains $m$ integers $h’_1, h’_2, \dots, h’_m$ ($1 \leq h’_i \leq 10^9$), where $h’_i$ represents the Health of Stewed-chicken’s $i$-th minion.
For each test file, it is guaranteed that the sum of all $n$ across all test cases does not exceed $5 \times 10^5$, and the sum of all $m$ across all test cases does not exceed $5 \times 10^5$.
Output
For each test case, output “Yes” if Fried-chicken can eliminate all of Stewed-chicken’s minions; otherwise, output “No”.
You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.
Solving
|
|