[Solution] Chef and Gym solution codechef

Chef and Gym solution codechef – Chef has decided to join a Gym in ChefLand and if possible, also hire a personal trainer at the gym. The monthly cost of the gym is XX and personal training will cost him an additional YY per month. Chef’s total budget per month is only ZZ. Print 1 if Chef can only join the gym, 2 if he can also have a personal trainer, and 0 if he can’t even join the gym.

[Solution] Chef and Gym solution codechef

Note that if Chef wants to hire a personal trainer, he must join the gym — he cannot hire the trainer without joining the gym.

Input Format

  • The first line of input will contain a single integer TT, denoting the number of test cases. Then the test cases follow.
  • Each test case consists of a single line of input containing three space-separated integers X,Y,ZX,Y,Z.

Output Format

For each test case, output in a single line 2 if Chef can go to the gym and have a trainer, 1 if Chef can only go to the gym, 0 if he can’t even go to the gym.

[Solution] Chef and Gym solution codechef

  • 1T1001≤T≤100
  • 1X,Y,Z1001≤X,Y,Z≤100

Sample Input 1 

4
1 2 3
10 12 13
23 1 22
23 1 63

Sample Output 1 

2
1
0
2

Chef and Gym solution Explanation

Test case 11: Since the total cost of Chef getting a gym membership and a trainer is 1+2=31+2=3 which is equal to his budget of 33, Chef can get both a gym membership and a trainer.

Test case 22: Since the total cost of Chef getting a gym membership and a trainer is 10+12=2210+12=22 which is greater than his budget of 1313, he can’t get both a gym membership and a trainer. However, the cost of the gym membership is 1010 which is less than his budget of 1313, so Chef can get only a gym membership.

Test case 33: Since the cost of Chef getting a gym membership is 2323 which is greater than his budget of 2222, Chef can’t even get the gym membership.

Test case 44: The same costs as the previous test, but this time Chef has enough money to afford both the membership and a personal trainer.

For Solution

Click here

Leave a Comment