cswork / OAOpen practice workspace

UberOA #9

Phone Battery Charging

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)SimulationStacks & Heaps

You have n batteries. Battery i lasts capacity[i] units and, after being fully drained, needs recharge[i] units to be ready again. You must keep a phone running for t units, swapping batteries instantly when one runs out. Multiple batteries can recharge in parallel. Return the number of batteries you can fully drain within the t units.

Constraints

  • 1 ≤ t ≤ 5000
  • 1 ≤ capacity.length ≤ 100
  • 1 ≤ capacity[i], recharge[i] ≤ 100
  • recharge.length == capacity.length
solution(t = 8, capacity = [5, 5], recharge = [7, 8]) = 2

Editorial

Loading solution…