2212. Maximum Points in an Archery Competition

Difficulty:
Related Topics:
Similar Questions:

Problem

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

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. Now, 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:

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.

  Constraints:

Solution (Java)

class Solution {
    private final int[] ans = new int[12];
    private final int[] ans1 = new int[12];
    private int max = 0;

    public int[] maximumBobPoints(int numArrows, int[] aliceArrows) {
        solve(numArrows, aliceArrows, 11, 0);
        return ans1;
    }

    private void solve(int numArrows, int[] aliceArrows, int index, int sum) {
        if (numArrows <= 0 || index < 0) {
            if (max < sum) {
                max = sum;
                ans1[0] = Math.max(ans[0], ans[0] + numArrows);
                System.arraycopy(ans, 1, ans1, 1, 11);
            }
            return;
        }
        if (aliceArrows[index] + 1 <= numArrows) {
            ans[index] = aliceArrows[index] + 1;
            solve(numArrows - (aliceArrows[index] + 1), aliceArrows, index - 1, sum + index);
            ans[index] = 0;
        }
        solve(numArrows, aliceArrows, index - 1, sum);
    }
}

Explain:

nope.

Complexity: