You and your friends have gotten together for a Trivia night at the local pub. Each question is worth a number of points; the i-th element of points corresponds to the score received if you correctly answer the i-th question, but you lose that many points if you answer it incorrectly. The questions are given in the order specified in points, and you must answer each question before the next is asked.
In addition, after each correct answer you will receive a token, and you keep all of your tokens if you answer a question incorrectly. If you then have tokensNeeded tokens, the pub will immediately take all of your tokens and award you additional bonus points. The bonuses are different for each question; element i of bonuses corresponds to the bonus you receive if you win the bonus on question i. Note that it is possible to receive multiple bonuses during the game (see example 0).
You know the answer to all the questions and want to maximize the number of points that you receive. Return the maximum points that you can receive if you correctly choose which questions to answer.
|