Problem Statement:

The game is simple. You initially have ‘H’ amount of health and ‘A’ amount of armor. At any instant you can live in any of the three places - fire, water and air. After every unit time, you have to change your place of living. For example if you are currently living at fire, you can either step into water or air.

If you step into air, your health increases by 3 and your armor increases by 2

If you step into water, your health decreases by 5 and your armor decreases by 10

If you step into fire, your health decreases by 20 and your armor increases by 5

If your health or armor becomes <=0, you will die instantly

Find the maximum time you can survive.


The first line consists of an integer t, the number of test cases. For each test case there will be two positive integers representing the initial health H and initial armor A.


For each test case find the maximum time you can survive.


Note: You can choose any of the 3 places during your first move.


Input Constraints:

1 <= t <= 10
1 <= H, A <= 1000


Sample Input:

2 10
4 4
20 8

Sample Output:


hide comments
zerodark: 2020-03-04 05:33:28

No need of dp greedy approach works.

bmad_221: 2020-01-22 14:54:55


killer_knight: 2019-10-14 20:21:14

make sure while using [spoiler]..your [spoiler] should be greater than [spoiler].. [spoiler] is working fine :)

Last edit: 2019-11-04 16:22:39
scolar_fuad: 2019-08-13 19:27:55

recusrive solution is so easy my 30th

toolatetostart: 2019-06-13 13:53:29

[spoiler] will pass,and be sure first [spoiler] as [spoiler]

Last edit: 2019-06-20 12:38:09
nisiddharth: 2019-05-26 17:42:37

I solved it using [spoiler], first [spoiler] code at SPOJ my me!

kamesh11: 2019-05-18 11:30:56

[spoiler], not [spoiler]!!! :)

Last edit: 2019-06-20 12:38:44
nitish235: 2019-01-24 17:54:18

[spoiler] !!

Last edit: 2019-03-11 23:40:39
piyushchavan88: 2018-12-15 19:18:02

Do note that [spoiler], i.e [spoiler], and so on.
AC in 3rd go !

Last edit: 2019-01-05 11:36:01
nahi_ho_payega: 2018-12-11 16:26:33

easy using [spoiler]

Added by:cegprakash
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64