TopCoder problem "TriviaGame" used in SRM 395 (Division II Level Three)

Problem Statement


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.



Parameters:int[], int, int[]
Method signature:int maximumScore(int[] points, int tokensNeeded, int[] bonuses)
(be sure your method is public)


-points will contain between 1 and 50 elements, inclusive.
-Each element of points will be between 0 and 1000, inclusive.
-tokensNeeded will be between 1 and 50, inclusive.
-bonus will contain the same number of elements as points.
-Each element of bonus will be between 0 and 10000, inclusive.


{1, 2, 3, 4, 5, 6}
{4, 4, 4, 4, 4, 4}
Returns: 29
Answering all six questions correctly will yield the best score in this case, obtaining the bonus after answering the 3rd and 6th questions.
{1, 2, 3, 4, 5, 6}
{1, 1, 1, 20, 1, 1}
Returns: 39
Here, it is better to get the first question wrong so that you get the big bonus on the 4th question.
{150, 20, 30, 40, 50}
{0, 0, 0, 250, 0}
Returns: 500
Here, your optimal strategy is to get the second question wrong. Then, you will have 3 tokens after the 4th question, so that you can cash in on the big bonus.
{500, 500, 500, 0, 500}
{0, 0, 0, 500, 0}
Returns: 2000

Problem url:

Problem stats url:




PabloGilberto , Olexiy , lovro , ivan_metelsky

Problem categories:

Dynamic Programming