Under construction

Still being built. Things may change

Soldiers (Small)

Time limit5sMemory limit512 MB

Summary
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 NN soldiers. Soldier ii has an attack value AiA_i and a defense value DiD_i.

Before the game starts, the two generals take turns selecting soldiers, and Alice selects first. Let SS be the set of soldiers selected so far. On a turn, a player may select soldier xx if at least one of these two conditions holds:

  • Ax>AsA_x > A_s for every soldier ss in SS
  • Dx>DsD_x > D_s for every soldier ss in SS

While SS is empty both conditions hold, so the first selection may be any soldier. A soldier already in SS 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 TT. Each test case begins with a line holding NN, the number of soldiers. The next NN lines each hold two integers AiA_i and DiD_i, the attack and defense values of the ii-th soldier.

Constraints:

  • 1≤T≤101 \le T \le 10
  • 1≤N≤2001 \le N \le 200
  • 1≤Ai,Di≤100001 \le A_i, D_i \le 10000

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.

Examples2

  1. Example 1

    Input
    3
    3
    10 2
    1 10
    10 3
    3
    10 1
    10 10
    1 10
    3
    10 2
    1 10
    4 9
    
    Expected output
    Case #1: NO
    Case #2: YES
    Case #3: YES
    
  2. Example 2

    Input
    1
    1
    7 9
    
    Expected output
    Case #1: YES