Maximum Light Up solution codechef

Maximum Light Up solution codechef

 

Chef has allocated himself a budget of PP rupees to buy Diwali crackers. There are only 33 types of crackers available in the market and each type of cracker can be bought any number of times.

  1. Fuljhari, where each costs aa rupees
  2. Anar, where each costs bb rupees
  3. Chakri, where each costs cc rupees

The crackers have the following interesting properties:-

  • A Fuljhari can be lit on its own
  • To light an Anar, you will need xx Fuljharis
  • To light a Chakri, you will need yy Fuljharis

What’s the maximum total of Anars and Chakris that Chef can light up with his given budget.

Input Format

  • First line of input will contain TT, the number of test cases. Then the test cases follow.
  • Each test case contains of a single line of input, six integers PPaabbccxx and yy.

Output Format

For each test case, output in a single line the maximum total of Anars and Chakris Chef can light up.

Constraints

  • 1T1051≤T≤105
  • 1P,a,b,c,x,y1091≤P,a,b,c,x,y≤109

Sample Input 1 

3
100 5 5 10 4 8
16 2 2 2 1 1
55 1 2 3 4 5

Sample Output 1 

4
4
9

Explanation

Test case 11:

Maximum Light Up solution codechef

  • Chef will buy 1616 Fuljhari’s and 44 Anar’s which in total costs him 165+45=10016⋅5+4⋅5=100 rupees.
  • Next, he uses 1616 Fuljhari’s to light 164=4164=4 Anar’s.
  • Since all the Fuljhari’s are over, he can’t light up any Chakri’s.
  • So in total, he is able to light up 4+0=44+0=4 Anar’s and Chakri’s.
  • There is no other allocation giving a better answer than this.

Test case 22:

  • Chef will buy 44 Fuljhari’s, 22 Anar’s and 22 Chakri’s which in total costs him 42+22+22=164⋅2+2⋅2+2⋅2=16 rupees.
  • Next, he uses 22 Fuljhari’s to light 21=221=2 Anar’s.
  • Next, he uses 22 Fuljhari’s to light 21=221=2 Chakri’s.
  • So in total, he is able to light up 2+2=42+2=4 Anar’s and Chakri’s.
  • The other possible allocation could be buying 44 Fuljhari’s, 33 Anar’s, and 11 Chakri.

Maximum Light Up solution codechef

 

 

Chef has allocated himself a budget of PP rupees to buy Diwali crackers. There are only 33 types of crackers available in the market and each type of cracker can be bought any number of times.

  1. Fuljhari, where each costs aa rupees
  2. Anar, where each costs bb rupees
  3. Chakri, where each costs cc rupees

Maximum Light Up solution codechef

The crackers have the following interesting properties:-

  • A Fuljhari can be lit on its own
  • To light an Anar, you will need xx Fuljharis
  • To light a Chakri, you will need yy Fuljharis

What’s the maximum total of Anars and Chakris that Chef can light up with his given budget.

Input Format

  • First line of input will contain TT, the number of test cases. Then the test cases follow.
  • Each test case contains of a single line of input, six integers PPaabbccxx and yy.

Output Format

For each test case, output in a single line the maximum total of Anars and Chakris Chef can light up.

Constraints

  • 1T1051≤T≤105
  • 1P,a,b,c,x,y1091≤P,a,b,c,x,y≤109

Sample Input 1 

3
100 5 5 10 4 8
16 2 2 2 1 1
55 1 2 3 4 5

Sample Output 1 

4
4
9

Explanation

Test case 11:

  • Chef will buy 1616 Fuljhari’s and 44 Anar’s which in total costs him 165+45=10016⋅5+4⋅5=100 rupees.
  • Next, he uses 1616 Fuljhari’s to light 164=4164=4 Anar’s.
  • Since all the Fuljhari’s are over, he can’t light up any Chakri’s.
  • So in total, he is able to light up 4+0=44+0=4 Anar’s and Chakri’s.
  • There is no other allocation giving a better answer than this.

Test case 22:

  • Chef will buy 44 Fuljhari’s, 22 Anar’s and 22 Chakri’s which in total costs him 42+22+22=164⋅2+2⋅2+2⋅2=16 rupees.
  • Next, he uses 22 Fuljhari’s to light 21=221=2 Anar’s.
  • Next, he uses 22 Fuljhari’s to light 21=221=2 Chakri’s.
  • So in total, he is able to light up 2+2=42+2=4 Anar’s and Chakri’s.
  • The other possible allocation could be buying 44 Fuljhari’s, 33 Anar’s, and 11 Chakri.

Maximum Light Up solution codechef

Leave a Reply

Your email address will not be published. Required fields are marked *

*