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 points are then calculated as follows:
	
		The target has integer scoring sections ranging from 0 to 11 inclusive.
		For each section of the target with score k (in between 0 to 11), say Alice and Bob have shot ak and bk arrows on that section respectively. If ak &gt;= bk, then Alice takes k points. If ak &lt; bk, then Bob takes k points.
		However, if ak == bk == 0, then nobody takes k points.
	
	



	
	For example, if Alice and Bob both shot 2 arrows on the section with score 11, then Alice takes 11 points. On the other hand, if Alice shot 0 arrows on the section with score 11 and Bob shot 2 arrows on that same section, then Bob takes 11 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. 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.

&nbsp;
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.


&nbsp;
Constraints:


	1 &lt;= numArrows &lt;= 105
	aliceArrows.length == bobArrows.length == 12
	0 &lt;= aliceArrows[i], bobArrows[i] &lt;= numArrows
	sum(aliceArrows[i]) == numArrows


class Solution:
    def maximumBobPoints(self, numArrows: int, aliceArrows: List[int]) -> List[int]:
        self.bestScore = 0
        self.bestBobArrows = None
        
        def backtracking(k, remainArrows, score, bobArrows):
            if k == 12:
                if score > self.bestScore:
                    self.bestScore = score
                    self.bestBobArrows = bobArrows[::]
                return
            
            backtracking(k+1, remainArrows, score, bobArrows)  # Bob loses
            
            # Bob wins
            arrowsNeeded = aliceArrows[k] + 1
            if remainArrows >= arrowsNeeded:
                old = bobArrows[k]
                bobArrows[k] = arrowsNeeded  # set new
                backtracking(k+1, remainArrows - arrowsNeeded, score + k, bobArrows)
                bobArrows[k] = old  # backtrack
                
        backtracking(0, numArrows, 0, [0] * 12)
		# In case of having remain arrows then it means in all sections Bob always win 
        # then we can distribute the remain to any section, here we simple choose first section.
        self.bestBobArrows[0] += numArrows - sum(self.bestBobArrows)
        return self.bestBobArrows
   class Solution {
        int bobPoint = 0;
        int[] maxbob = new int[12];
        public int[] maximumBobPoints(int numArrows, int[] aliceArrows) {
            int[] bob = new int[12];
            calculate(aliceArrows, bob, 11, numArrows, 0); //Start with max point that is 11
            return maxbob;
        }
        public void calculate(int[] alice, int[] bob, int index, int remainArr, int point) {
            if(index < 0 || remainArr <= 0) {
                if(remainArr > 0)
                    bob[0] += remainArr;
                if(point > bobPoint) { // Update the max points and result output
                    bobPoint = point;
                    maxbob = bob.clone();
                }
                return;
            }
            //part 1: assign 1 more arrow than alice
            if(remainArr >= alice[index]+1) {
                bob[index] = alice[index] + 1;
                calculate(alice, bob, index-1, remainArr-(alice[index]+1), point + index);
                bob[index] = 0;
            }
            //part 2: assign no arrow and move to next point
            calculate(alice, bob, index-1, remainArr, point);
            bob[index] = 0;
        }
    }
class Solution {
public:
    int maxscore; 
    vector<int> ans;
    
    void helper(vector<int> &bob, int i, vector<int>& alice, int remarrows, int score)
    {
        if(i == -1  or  remarrows <= 0)
        {
            if(score >= maxscore)
            {
                maxscore = score; 
                ans = bob; 
            }
            return; 
        }
        
        helper(bob, i-1, alice, remarrows, score);
        if(remarrows > alice[i])
        {
            bob[i] = alice[i] + 1;
            remarrows -= (alice[i] + 1);
            score += i; 
            helper(bob, i-1, alice, remarrows, score);
            bob[i] = 0;
        } 
    }
    
    vector<int> maximumBobPoints(int numArrows, vector<int>& aliceArrows) {
        vector<int> bob(12, 0);
        maxscore = INT_MIN; 
        helper(bob, 11, aliceArrows, numArrows, 0);
        
        int arrows_used = 0; 
        for(int a : ans)
            arrows_used += a; 
        if(arrows_used < numArrows)
            ans[0] += (numArrows - arrows_used);
        return ans; 
    }
};
var maximumBobPoints = function(numArrows, aliceArrows) {
  let max = 0, n = aliceArrows.length, res;
  backtrack(numArrows, 0, 0, Array(n).fill(0));
  return res;

  function backtrack(arrows, idx, points, bobArrows) {
    if (idx === n || arrows === 0) {
      let origVal = bobArrows[n - 1];
      if (arrows > 0) bobArrows[n - 1] += arrows; // put extra arrows in any slot
      if (points > max) {
        max = points;
        res = [...bobArrows]; 
      }
      bobArrows[n - 1] = origVal;
      return;
    }

    backtrack(arrows, idx + 1, points, bobArrows); // don't use any arrows
    if (aliceArrows[idx] + 1 <= arrows) { // use aliceArrows[idx] + 1 arrows to gain idx points
      bobArrows[idx] = aliceArrows[idx] + 1;
      backtrack(arrows - (aliceArrows[idx] + 1), idx + 1, points + idx, bobArrows);
      bobArrows[idx] = 0;
    }
  }  
};
Maximum Points in an Archery Competition