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
sophozaar: 2018-12-11 15:06:10

Nice [spoiler] xD

Last edit: 2018-12-11 15:10:02
ankitpriyarup: 2018-12-07 16:48:56

Solved using [Spoiler] XD

prachij: 2018-10-19 12:42:42

Mine 20th!! AC in one go :D

masterchef2209: 2018-10-08 12:30:12

did it without [spoiler], only [spoiler]

Last edit: 2018-10-15 20:46:20
jmr99: 2018-10-06 11:15:57

[spoiler] is love .

himanshu2620: 2018-10-02 04:15:26

Good problem & so much fun reading these comments #[spoilers] now!!

shashankpathak: 2018-08-19 12:48:56

@aakashjaiswal your comment helped its basic [spoiler]. Nice problem to gain confidence in [spoiler] for beginners

Last edit: 2018-08-22 15:43:28
aakashjaiswal: 2018-07-03 21:00:15

while applying [spoiler] should be taken [spoiler] may give a runtime error.A [spoiler] works just fine.

Last edit: 2018-08-22 15:44:14
kushagra98: 2018-06-05 20:10:00

[spoiler] :3

Last edit: 2018-10-15 20:46:39
jacobian_det: 2018-02-13 07:51:28

my 50th on SPOJ, AC in one go :)

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