#2212

Maximum Points in an Archery Competition

specialist · 860 · lc medium +31 · verified · 51.4% accepted · 515 likes · top 40%

Description

Alice and Bob compete in an archery competition with the following scoring rules:

- Alice shoots numArrows arrows first, then Bob shoots numArrows arrows.

- The target has scoring sections numbered 0 to 11. For section k, if Alice shot ak arrows and Bob shot bk arrows on it:

- Alice scores k points if ak >= bk.

- Bob scores k points if ak < bk.

- If both shot 0 arrows, neither scores.

For instance, if both shot 2 arrows on section 11, Alice gets 11 points. If Alice shot 0 and Bob shot 2 on section 11, Bob gets 11 points.

You are given numArrows and aliceArrows (an array of size 12 with Alice's arrow counts per section). Bob wants to maximize his total score.

Return bobArrows, an array of size 12 giving Bob's arrow distribution per section. The values must sum to numArrows. Any valid maximum-score solution is accepted.

Example 1:

Input: numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0]
Output: [0,0,0,0,1,1,0,0,1,2,3,1]
Explanation: The table above shows how the competition is scored.
Bob earns a total point of 4 + 5 + 8 + 9 + 10 + 11 = 47.
It can be shown that Bob cannot obtain a score higher than 47 points.

Example 2:

Input: numArrows = 3, aliceArrows = [0,0,1,0,0,0,0,0,0,0,0,2]
Output: [0,0,0,0,0,0,0,0,1,1,1,0]
Explanation: The table above shows how the competition is scored.
Bob earns a total point of 8 + 9 + 10 = 27.
It can be shown that Bob cannot obtain a score higher than 27 points.

Code

1
2
3