Ctrl K

Outshoot the Rival

Medium
A target has 12 sectors worth 0 to 11 points. A rival has already shot: sector k holds rival[k] of the rival's arrows. Now it is Bob's turn; he has arrows arrows and can send each one into any sector. Bob takes sector k if he has strictly more arrows in it than the rival; otherwise the sector stays with the rival (a sector nobody hit earns no one anything). Bob's score is the total value of his sectors. Bob shoots like this: - into each sector he wants, he sends exactly rival[k] + 1 arrows; - all remaining arrows go into sector 0. Choose the set of sectors that gives Bob the highest score. If several sets tie, compare them from sector 11 downwards: at the first sector where they differ, prefer the set in which Bob does **not** take that sector. Return an array of 12 numbers: how many arrows Bob fires into each sector. The array sums to arrows.
Example 1
arrows=4, rival=[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1] → [0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0]

Sector 11 costs 2 arrows, 10 costs 3, 9 costs 2, and sectors 1–8 cost one each. Both 11 + 8 + 7 and 8 + 7 + 6 + 5 give 26 points with 4 arrows. Comparing from sector 11 down, the second set skips sector 11, so it wins the tie.

Example 2
arrows=3, rival=[3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] → [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]

Sectors 1 to 11 are all empty, so one arrow takes each: Bob takes 11, 10 and 9 for 30 points.

Example 3
arrows=6, rival=[0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2] → [0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0]
Constraints
  • 1 ≤ arrows ≤ 10⁵
  • len(rival) = 12
  • 0 ≤ rival[k] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPicks With the Full OR MediumColumns That Cover Rows MediumStrongest Product Team MediumMoves Between Offices HardXOR of Every Subset Easy
loading Python…
Input
arrows=4, rival=[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1]
Expected
[0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0]

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