
Venus: Decreases health by 4, decreases armour by 8.
Mars: Increases health by 3, increases armour by 2.
Saturn: Decreases health by 10, increases armour by 5.
You can choose any of the 3 planets during your first move.
The first line of input contains a single integer T, representing the number of test cases.
Then the T test cases follow.
The first line of every test case contains 2 single space-separated integers representing initial health and initial armour respectively.
For every test case, print a single integer representing the maximum time Ninja can survive.
The output of each test case is printed in a separate line.
You don’t have to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= H, A <= 10^3
Where ‘T’ denotes the number of test cases, ‘H’ is the initial health and ‘A’ is the initial armour.
Time Limit: 1sec
The idea is simple, we will check all the possible ways of choosing planets with the help of recursion and find out which combination gives maximum time.
Along with this, we will prefer to move Mars whenever possible as it is always beneficial to make a move to Mars.
Our last approach was very simple and easy, but its time complexity was of exponential order. We can improve our solution by taking care of the overlapping subproblems. Thus, we will eliminate the need for solving the same subproblems again and again by storing them in a lookup table. This approach is known as Memoization
In the earlier approach, we tried to find all the possible solutions and select the one with maximum survival time, but we really do not need to find all the possible solutions. Instead, we will use some greedy approach. We can see that it is always beneficial to go to Mars so for every odd second, we will go to Mars. Now for even seconds, we are left with Venus and Saturn. So we will choose Venus if possible else we will choose Saturn, as Venus decreases health less than Saturn.