This page is still under construction.

Parts of this page are still being built. What you see may change.

Attack Order

Time limit2sMemory limit512 MB

Summary
Given minions with attacks a_i and buff values b_i, decide whether some left-to-right order keeps attacks non-increasing for every possible choice of buff targets.
Level

Medium6 of 10

Topics
Greedy, Sorting, Math
Solved
No attempts yet

Problem

In a certain game, you control a board of nn minions numbered from 11 to nn. Each minion ii has an integer a_ia\_i, called its attack.

For the upcoming fight, you arrange the minions in a line from left to right.

After that, some of the minions' attacks get buffed. The ability of each minion ii reads "Before the fight, increase the attack of another random minion by b_ib\_i". Formally, for each ii, an arbitrary minion j≠ij \ne i is chosen and its attack a_ja\_j is increased by b_ib\_i.

The buff targets are chosen independently and the buffs happen simultaneously. In particular, the attack of any minion can get buffed multiple times.

You want the attacks of the minions to be non-increasing from left to right after all the buffs happen. Determine whether it is possible to arrange the minions so that this holds regardless of how the buff targets are chosen.

Input

Each input contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). The test cases follow.

The first line of each test case contains a single integer nn (2≤n≤1002 \le n \le 100).

The ii-th of the next nn lines contains two integers a_ia\_i and b_ib\_i (0≤a_i,b_i≤1060 \le a\_i, b\_i \le 10^6).

Output

For each test case, print "Yes" if it is possible to arrange the minions so that their attacks are non-increasing regardless of how the buff targets are chosen, and "No" otherwise.

Notes

In the first example, the minions buff each other. The attacks of minions 11 and 22 during the fight are always 2020 and 3535, respectively. You can arrange the minions in the order ⟨2,1⟩\langle 2, 1 \rangle.

In the second example, only minion 22 buffs another minion. One valid ordering is ⟨3,1,2⟩\langle 3, 1, 2 \rangle. If minion 22 buffs minion 11, the attacks of the minions, from left to right, are ⟨10,10,7⟩\langle 10, 10, 7 \rangle. If minion 22 buffs minion 33, the attacks are ⟨13,7,7⟩\langle 13, 7, 7 \rangle. Both sequences are non-increasing.

Examples1

  1. Example 1

    Input
    3
    2
    15 25
    10 5
    3
    7 0
    7 3
    10 0
    3
    10 10
    20 20
    30 30
    
    Expected output
    Yes
    Yes
    No