Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Bob's Dilemma

By oorpib · Limits 1s, 512 MB

Alice and Bob have been playing a game on Android phone. It is a PVP game. They can play against each other. They are playing it for a little time, but they have learned the game’s rules.

Initially, each player has only one Hero. Each hero has Certain Health Points (H), Attack Power (A), Ability Level (L) and Boost Attack Power (B).

The game is played in turns. But who will attack first?

It’s decided by in game coin toss (C).

The hero of the toss winner (let Player1 is the toss winner) starts attacking first. So first Player1’s hero deals damage equal to its attack power (A1). Then player2’s hero deals damage equal to its attack power (A2) and then again the hero of player1 attacks and so on. A player wins the game if the Health Points of opponent’s hero drop to 0 or less, we can say the hero died.

After completing every 5th strike, a hero immediately burst into rage and deals some extra damages equal to its Boost Attack Power. And the Boost attack Power of this hero increases by 1 i.e. if the first Boost attack deals 10 point damage (after completing its 5th strike) to the opponent, the second boost attack will deal 11 point damage (after completing its 10th strike), and so on. So we can say using Boost Attack helps them winning faster . But there’s a catch.

Each hero could activate and use its Boost Attack Power only after having at least ability level 5.

Now, Bob is trying to guess if he can be the winner given each player’s hero’s current Health Points (H), Attack Power (A), Ability Level (L), Boost Attack power (B) and the winner of the coin toss (C).

Can you solve it for Bob?

Input

The first line contains the number of test cases T (1≤ T ≤ 100000). For each test case the first line contains C ( C = 0 or 1), 0 if Bob won the toss, and 1 if Alice won the toss.

The next two lines contain the description of each hero H, A, L, B ( 1≤ H ≤ 10^10 , 1≤ A ≤ 10^10, 1≤ B ≤ 10^10, 1 ≤ L ≤ 50), First being the description of Alice’s hero, the second is the description of Bob’s hero.

Output

For each test case print ‘yes’ (without the quotes) if Bob can win or ‘no’ (without the quotes) if he can’t win in the separate line. Output is case-sensitive.

Sample

InputOutput
2
1
100 20 10 7
240 10 10 7
0
100 20 4 7
180 10 4 7
yes
no

The first case, Alice’s hero attacks first and Bob’s hero’s health decreases by Alice’s hero as follows → 220 200 180 160 133 113 93 73 53 25 5 -15.

And due to Bob’s attack , Alice’s hero’s health decreases as follows → 90 80 70 60 43 33 23 13 3 -15

As Bob’s hero needs less attack than Alice so, he wins.

As for Second case none of them haven’t activated their Boost Attack Power, so they can’t use their Boost Attack . Alice needs less attack so Bob can’t win.

    Discussion

    Statistics


    68% Solution Ratio

    AashiqEarliest, 1M ago

    s_dasailorFastest, 0.0s

    AashiqLightest, 393 kB

    Zrrr97Shortest, 684B

    Submit

    Login to submit

    Editorial

    Solution Technique : Binary Search. Editorial : To find if bob can win, we have to find the number...

    Related Contests