682. Maximum Points in an Archery Competition

HardStackBitmaskGreedy

There are 12 scoring sections numbered 0-11 (section i is worth i points). Alice has already shot, with aliceArrows[i] arrows in section i. Bob has numArrows arrows; Bob wins section i (and its i points) only by shooting strictly more arrows there than Alice. Return an allocation of Bob's arrows (length 12, summing to numArrows) that maximizes Bob's score; leftover arrows go to section 0. The input is JSON {numArrows, aliceArrows}.

Input: JSON {numArrows, aliceArrows}.

Output: Array — Bob's arrow allocation across the 12 sections.

Examples

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: An allocation maximizing Bob's 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: Win the highest section affordable.
Example 3
Input: {"numArrows":1,"aliceArrows":[0,0,0,0,0,0,0,0,0,0,0,0]}
Output: [0,0,0,0,0,0,0,0,0,0,0,1]
Explanation: Win section 1 for one point.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →