Solution Technique : Binary Search.

Editorial : To find if bob can win, we have to find the number of attack each player needs to defeat their opponent.

If we dig a bit deeper, we can find a pattern. Let A (attack Power) , L (ability level), B (boost attack power), If the troop’s ability level is below 5 , we can calculate the number of attack by simple division as they haven’t activated their boost attack power. H being the health of opponent troop, P (numbers of attack) = H / A; But if the Ability Level is at least 5, then the number of attack can be calculated as follows, let the number of boost needed to defeat opponent’s health be X and N be the number of attack (using boost) , here N can be less than, greater than or equal to the actual number of attack,

N =((A × 5) + B) + ((A × 5) + B+1) + ((A × 5) + B+2) + ……. + ((A × 5) + B +(X-1))

N = ((A×5) * X) + (B + (B+1) + (B+2) +…. + (B + (X-1))

N = ((A×5) * X) + (B× X) + (0 +1 +2 + …. (X-1))

We can then find the X Using Binary search and then Calculate the rest of attack if needed.

Overall Complexity : t log (n) ; (base 2) , t being the test cases.

Contributors

Statistics

70% Solution Ratio
AashiqEarliest, Aug '20
Kuddus.6068Fastest, 0.0s
AashiqLightest, 393 kB
Zrrr97Shortest, 684B
Toph uses cookies. By continuing you agree to our Cookie Policy.