Chef and Chocolates solution codechef

Chef and Chocolates solution codechef

Chef has XX 5 rupee coins and YY 10 rupee coins. Chef goes to a shop to buy chocolates for Chefina where each chocolate costs ZZ rupees. Find the maximum number of chocolates that Chef can buy for Chefina.

Input Format

  • The first line contains a single integer TT — the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains three integers XXYY and ZZ — the number of 5 rupee coins, the number of 10 rupee coins and the cost of each chocolate.

Output Format

Chef and Chocolates solution codechef

For each test case, output the maximum number of chocolates that Chef can buy for Chefina.

Constraints

  • 1T1001≤T≤100
  • 1X,Y,Z10001≤X,Y,Z≤1000

Chef and Chocolates solution codechef

Sample Input 1 

4
10 10 10
3 1 8
8 1 3
4 4 1000

Sample Output 1 

15
3
16
0

Explanation

Chef and Chocolates solution codechef

Test case 11: Chef has 105+1010=15010⋅5+10⋅10=150 rupees in total. Since each chocolate costs 1010 rupees, Chef can spend all 150150 rupees and buy 1515 chocolates for Chefina.

Test case 22: Chef has 35+110=253⋅5+1⋅10=25 rupees in total. Since each chocolate costs 88 rupees, Chef can buy a maximum of 33 chocolates for Chefina, leaving him with 11 rupee.

Test case 33: Chef has 85+110=508⋅5+1⋅10=50 rupees in total. Since each chocolate costs 33 rupees, Chef can buy a maximum of 1616 chocolates for Chefina, leaving him with 22 rupee.

Test case 44: Chef has 45+410=604⋅5+4⋅10=60 rupees in total. Since each chocolate costs 10001000 rupees, Chef can buy no chocolate for Chefina, leaving him with 6060 rupees.

SOLUTION

Click Here

Leave a Comment

Your email address will not be published.