Soldiers (Small)
Time limit5sMemory limit512 MB
Two players alternately pick soldiers whose attack or defense beats everything picked so far; decide if the first player can guarantee ending with more picks.
- Level
Medium7 of 10
- Topics
- Game theory, Sorting, Greedy, Implementation
- Solved
- No attempts yet
Problem
General Alice and General Bob play a war game with soldiers. Soldier has an attack value and a defense value .
Before the game starts, the two generals take turns selecting soldiers, and Alice selects first. Let be the set of soldiers selected so far. On a turn, a player may select soldier if at least one of these two conditions holds:
- for every soldier in
- for every soldier in
While is empty both conditions hold, so the first selection may be any soldier. A soldier already in can never be selected again, because it does not beat its own attack or its own defense. When the player to move has no legal selection, the selection process ends and the game starts.
Alice wants to finish with more soldiers than Bob, and Bob wants to stop her. Both generals play optimally toward their own goal. Decide whether Alice succeeds.
Input
The first line contains the number of test cases . Each test case begins with a line holding , the number of soldiers. The next lines each hold two integers and , the attack and defense values of the -th soldier.
Constraints:
Output
For each test case, print one line in the form Case #x: y. Here x is the test case number starting from 1, and y is YES if Alice can guarantee that she selects more soldiers than Bob no matter how Bob plays, and NO otherwise.