click below for solution

Monday, 31 January 2022

Kill the Monster solution|educational codeforces round 122 (rated for div 2)

                                               C. Kill the Monster

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Monocarp is playing a computer game. In this game, his character fights different monsters.

A fight between a character and a monster goes as follows. Suppose the character initially has health hC and attack dC; the monster initially has health hM and attack dM. The fight consists of several steps:

  1. the character attacks the monster, decreasing the monster's health by dC;
  2. the monster attacks the character, decreasing the character's health by dM;
  3. the character attacks the monster, decreasing the monster's health by dC;
  4. the monster attacks the character, decreasing the character's health by dM;
  5. and so on, until the end of the fight.

The fight ends when someone's health becomes non-positive (i. e. 0 or less). If the monster's health becomes non-positive, the character wins, otherwise the monster wins.

Monocarp's character currently has health equal to hC and attack equal to dC. He wants to slay a monster with health equal to hM and attack equal to dM. Before the fight, Monocarp can spend up to k coins to upgrade his character's weapon and/or armor; each upgrade costs exactly one coin, each weapon upgrade increases the character's attack by w, and each armor upgrade increases the character's health by a.

Can Monocarp's character slay the monster if Monocarp spends coins on upgrades optimally?

Input

The first line contains one integer t (1t5104) — the number of test cases. Each test case consists of three lines:

The first line contains two integers hC and dC (1hC10151dC109) — the character's health and attack;

The second line contains two integers hM and dM (1hM10151dM109) — the monster's health and attack;

The third line contains three integers kw and a (0k21050w1040a1010) — the maximum number of coins that Monocarp can spend, the amount added to the character's attack with each weapon upgrade, and the amount added to the character's health with each armor upgrade, respectively.

The sum of k over all test cases does not exceed 2105.

Output

For each test case, print YES if it is possible to slay the monster by optimally choosing the upgrades. Otherwise, print 

Note

In the first example, Polycarp can spend one coin to upgrade weapon (damage will be equal to 5), then health during battle will change as follows: (hC,hM)=(25,9)(25,4)(5,4)(5,1). The battle ended with Polycarp's victory.

In the second example, Polycarp has no way to defeat the monster.

In the third example, Polycarp has no coins, so he can't buy upgrades. However, the initial characteristics are enough for Polycarp to win.

In the fourth example, Polycarp has 4 coins. To defeat the monster, he has to spend 2 coins to upgrade weapon and 2 coins to upgrade armor.

Solution:

solution link 1

if 1st link is not work then click on another link
Solution link 2

Solution link 3

Solution link 4

How to get link tutorial video link


  

No comments:

Post a Comment