Ctrl K

Training Before the Tournament

Easy
You enter a tournament and face n rivals one after another. You have stamina stamina and skill skill. The i-th rival is described by two numbers, drain[i] and gain[i]. To beat the i-th rival, your current stamina must be **strictly greater** than drain[i] and your current skill **strictly greater** than gain[i]. After the win your stamina drops by drain[i] and your skill grows by gain[i]. You must beat every rival. Before the tournament you may train: each hour of training adds 1 to either your stamina or your skill, your choice. Return the smallest number of training hours that lets you beat all rivals in order.
Example 1
stamina=4, skill=2, drain=[2, 3], gain=[1, 5] → 5

To survive both matches, stamina must exceed 2 + 3 = 5, so at least 6: +2 hours. With skill 2 you beat the first rival (1) and reach 3, but not the second (5); 3 more hours let you start at 5, reach 6 after the first win and beat 5. In total 2 + 3 = 5 hours.

Example 2
stamina=10, skill=8, drain=[3, 4], gain=[2, 6] → 0

Stamina 10 is enough (10 > 3, then 7 > 4) and so is skill (8 > 2, then 10 > 6), so no training is needed.

Constraints
  • n = drain.length = gain.length
  • 1 ≤ n ≤ 100
  • 1 ≤ stamina, skill, drain[i], gain[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCake Slices for Guests EasyStrength of the Weaker Partner EasyPlanting Along a Garden Row EasyMaking Change at the Kiosk EasyRise and Fall Lineup Easy
loading Python…
Input
stamina=4, skill=2, drain=[2, 3], gain=[1, 5]
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 169 tests on the server, hidden ones included.