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.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.
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.
n = drain.length = gain.lengthn ≤ 100stamina, skill, drain[i], gain[i] ≤ 100stamina=4, skill=2, drain=[2, 3], gain=[1, 5]
5
Run checks the first 3 tests in your browser. Submit checks all 169 tests on the server, hidden ones included.