IOI '96 - Veszprém, Hungary

A Game

Consider the following two-player game played with a sequence of N positive integers (2 ≤ N ≤ 100) laid onto a game board. Player 1 starts the game. The players move alternately by selecting a number from either the left or the right end of the sequence. That number is then deleted from the board, and its value is added to the score of the player who selected it. A player wins if his sum is greater than his opponents.

Write a program that implements the optimal strategy. The optimal strategy yields maximum points when playing against the "best possible" opponent. Your program must further implement an optimal strategy for player 2.

Input Format

Line 1 contains the integer N, the size of the board. The following line(s) will contain N integers between 1 and 200 inclusive that are the contents of the game board, from left to right.

Output Format

Two space-separated integers on a line: the score of player 1 followed by the score of player 2.

Sample Input

6
4 7 2 9
5 2

Sample Output

18 11

All Submissions
Best Solutions


Point Value: 10
Time Limit: 2.00s
Memory Limit: 32M
Added: Dec 22, 2013

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

It's quiet in here...