SINGLEUSE - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: iceknight1093
Testers: wuhudsm, satyam_343
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

Chef is fighting a boss with H health, and does X damage per attack.
At most once, Chef can use a special move and do Y damage.
What’s the minimum number of attacks Chef needs to defeat the boss?

EXPLANATION:

Since X \lt Y, it’s always optimal to use the special attack.
After using the special attack, the boss’ remaining health is H-Y.

This needs to be depleted using normal attacks, and since they do X damage each, the number of them needed is \left\lceil \frac{H-Y}{X}\right\rceil.
Here, \lceil \ \rceil denotes the ceiling function.

Including the first special attack, the answer is

1 + \left\lceil \frac{H-Y}{X}\right\rceil

TIME COMPLEXITY

\mathcal{O}(1) per test case.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
	h, x, y = map(int, input().split())
	print(1 + (h-y+x-1)//x)