[Question] Number of games

Title description

Consider a game played by two players. Before the game starts, a series of N numbers in a row are given. Two players take turns to take a number from the leftmost or rightmost end of the series of numbers. When all numbers have been taken, the game is over. At this time, the respective scores of the two players will be the sum of all the numbers taken by them. The player with the higher score wins.

Suppose you are the first one. Please write a program to develop the best strategy for a game. The best strategy refers to a numerical method that can get the highest score in the worst case (the situation where the latter’s strategy is the most unfavorable to him).

Input format

The first line, a positive integer N, the input data is guaranteed to be 1≤N≤100.

The second line, from left to right, gives N positive integers at the beginning of the game. These positive integers are guaranteed not to exceed 200.

Output format

One line, output two positive integers separated by spaces. They respectively represent the highest score of the first taker in the game in the worst case and the score of the second taker at this time.

input example

6

4 7 2 9 5 2

< strong>Sample output

18 11

Problem solution

Input sample

6

4 7 2 9 5 2

Sample output

18 11

Input Sample

6

4 7 2 9 5 2

Sample output

18 11

Problem solution

< /div>

< div class="col-md-11">

Question solution

Problem solution

Problem solution

Leave a Comment

Your email address will not be published.