cswork / OA打开练习工作台

UberOA #9

Phone Battery Charging

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)模拟/实现单调栈与堆

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