← 返回 capitalone 的题目列表Phone Battery Rotation With Recharge Times
类型:online_judge
Problem: Phone Battery Rotation With Recharge Times
Your phone battery is dead, but you need to keep the phone running for t minutes.
You have n swappable batteries:
capacity[i]: the number of minutes the phone can run on battery i when it is fully charged.
recharge[i]: the number of minutes needed to recharge battery i from 0% to 100%.
Rules (as described):
You start using battery 0.
When a battery is completely drained, you immediately switch to the next battery in cyclic order 0 -> 1 -> ... -> n-1 -> 0 -> ....
Once drained, a battery starts recharging immediately and becomes fully charged after recharge[i] minutes.
You may only switch to a battery if it is fully charged at the switch time.
Determine whether the phone can run continuously for t minutes under these rules:
If yes, return the total number of times you used a fully charged battery (each time you start consuming from a full battery counts once; the initial battery counts too).
If not, return -1.
I/O
Input: integer t, arrays capacity, recharge (same length n)
Output: an integer (number of full-battery usages) or -1
Constraints (reasonable OA assumptions)
1 <= n <= 2e5
1 <= t <= 1e18
1 <= capacity[i], recharge[i] <= 1e9
Example
t = 100
capacity = [2, 3, 4, 5]
recharge = [12, 8, 9, 10]
Output: the computed number of full-battery usages; if at any switch the target battery is not fully charged, output -1.
Example
Input
100
4
2 3 4 5
12 8 9 10
Output
(implementation-dependent; return -1 if a switch hits an unready battery, else the full-battery usage count)