devices lamps and a set of batteries: battery i can power one lamp for charges[i] minutes. Batteries cannot be recharged.
At the start you may put at most one battery into each lamp. After that, at any whole minute you may pull a battery out and put in another one — a fresh one or one taken from a different lamp; swaps are instant and unlimited.
Return the largest whole number of minutes for which all devices lamps can shine at the same time.devices=3, charges=[4, 4, 4, 3] → 5
15 minutes of charge for three lamps is 5 each. No battery holds more than 5, so the charge can be shared evenly: 5.
devices=2, charges=[20, 2, 3] → 5
The 20-minute battery could run one lamp for a long time, but the other lamp gets only 2 + 3 = 5 minutes, so both cannot shine longer than 5.
devices=1, charges=[1, 1, 1] → 3
One lamp runs on all three batteries in turn: 3 minutes.
devices ≤ charges.length ≤ 10⁵charges[i] ≤ 10⁹devices=3, charges=[4, 4, 4, 3]
5
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.