Ctrl K

Siege Volleys on the Walls

Hard
A fortress is guarded by several walls; wall i has armor[i] points of armor. A catapult fires one shot at a time. For every shot you pick one wall: it loses direct points of armor, while **every other** wall loses splash points from flying debris. A wall is down once its armor is zero or negative (shooting at a wall that is already down is allowed). Return the smallest number of shots after which every wall is down.
Example 1
armor=[5, 9, 2], direct=5, splash=2 → 3

Two shots at wall 1 leave the armor at [1, -1, -2]. A third shot at wall 0 gives [-4, -3, -4], and every wall is down. Two shots are not enough: wall 1 would need both, leaving wall 0 with only 4 damage.

Example 2
armor=[3, 3], direct=3, splash=1 → 2

The first shot hits wall 0: [0, 2]. The second hits wall 1: [-1, -1].

Example 3
armor=[4], direct=7, splash=1 → 1

A single wall, and one direct shot removes 7 points of armor.

Constraints
  • 1 ≤ armor.length ≤ 10⁵
  • 1 ≤ armor[i] ≤ 10⁹
  • 1 ≤ splash < direct ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMedian Across Two Arrays HardMinimum of a Shifted Array With Repeats HardFrame Around an Ink Blot HardSmaller Values to the Right HardWindow Sums Within a Band Hard
loading Python…
Input
armor=[5, 9, 2], direct=5, splash=2
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.