Maximum Points in an Archery Competition

Alice and Bob are opponents in an archery competition. The competition has set the following rules:

  • Alice first shoots numArrows arrows and then Bob shoots numArrows arrows.
  • The target has integer scoring sections ranging from 0 to 11 inclusive.
  • For each section of the target with score k, where k is between 0 and 11, say Alice and Bob have shot ak and bk arrows on that section respectively:
  • If ak >= bk, then Alice takes k points.
  • If ak < bk, then Bob takes k points.
  • If ak == bk == 0, then nobody takes k points.

You are given the integer numArrows and an integer array aliceArrows of size 12, which represents the number of arrows Alice shot on each scoring section from 0 to 11. Bob wants to maximize the total number of points he can obtain.

Return the array bobArrows which represents the number of arrows Bob shot on each scoring section from 0 to 11. The sum of the values in bobArrows should equal numArrows.

If there are multiple ways for Bob to earn the maximum total points, return any one of them.

Example 1
InputnumArrows = 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]
Bob earns points from sections 4, 5, 8, 9, 10, and 11 for a total of 47, which is the maximum possible score.
Example 2
InputnumArrows = 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]
Bob earns points from sections 8, 9, and 10 for a total of 27, which is the maximum possible score.

Constraints

  • 1 <= numArrows <= 10^5
  • aliceArrows.length == bobArrows.length == 12
  • 0 <= aliceArrows[i], bobArrows[i] <= numArrows
  • sum(aliceArrows[i]) == numArrows

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate