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
ankit kumar: 2015-06-21 13:34:22

thanks hitman tests code really helped

i_love_inu143: 2015-06-13 03:49:40

its a nice problem seems difficult while just seeing this problem. but the numerical provided make it easy!! you can check my code [spoiler removed]

Last edit: 2015-08-10 21:01:20
mkmostafa: 2015-04-23 20:48:58

it's a very nice problem....and an easy one also :D

prodijig: 2015-04-10 01:04:50

Last edit: 2015-04-10 02:15:07
GAURAV CHANDEL: 2015-04-04 07:39:38

Nice..[spoiler removed] approach...AC

Last edit: 2015-08-10 21:02:42
zorkan: 2015-03-19 11:28:45

Last edit: 2015-04-03 01:18:30
Abhinandan Agarwal: 2015-03-05 23:05:59

It is a good problem , but no [spoiler removed] is required. easy if you get the idea behind it, nice work problem setter :)

Last edit: 2015-03-28 16:34:43
Diptesh Patel: 2015-02-02 10:51:50

[Spoiler removed] :P

Last edit: 2015-02-26 12:40:38
do_do: 2015-01-31 14:19:45

working with all test cases i can think of.. still wrong answer. i tried hitman's test cases my code is working fine with those cases. :(
edit : tried 3 hours later with same code and got accepted :p

Last edit: 2015-01-31 20:25:08
kailash: 2015-01-15 07:13:15

@Rishab Joshi check the size of your array if you use [spoiler removed]

Last edit: 2015-03-28 16:35:06

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