[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

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1734 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.