TWENDS  Two Ends
In the twoplayer game “Two Ends”, an even number of cards is laid out in a row. On each card, face up, is written a positive integer. Players take turns removing a card from either end of the row and placing the card in their pile. The player whose cards add up to the highest number wins the game. Now one strategy is to simply pick the card at the end that is the largest — we’ll call this the greedy strategy. However, this is not always optimal, as the following example shows: (The first player would win if she would first pick the 3 instead of the 4.)
3 2 10 4
You are to determine exactly how bad the greedy strategy is for different games when the second player uses it but the first player is free to use any strategy she wishes.
Input
There will be multiple test cases. Each test case will be contained on one line. Each line will start with an even integer n followed by n positive integers. A value of n = 0 indicates end of input. You may assume that n is no more than 1000. Furthermore, you may assume that the sum of the numbers in the list does not exceed 1,000,000.
Output
For each test case you should print one line of output of the form:
In game m, the greedy strategy might lose by as many as p points.
where m is the number of the game (starting at game 1) and p is the maximum possible difference between the first player’s score and second player’s score when the second player uses the greedy strategy. When employing the greedy strategy, always take the larger end. If there is a tie, remove the left end.
Example
Input: 4 3 2 10 4 8 1 2 3 4 5 6 7 8 8 2 2 1 5 3 8 7 3 0 Output: In game 1, the greedy strategy might lose by as many as 7 points. In game 2, the greedy strategy might lose by as many as 4 points. In game 3, the greedy strategy might lose by as many as 5 points.
hide comments
rohit1507:
20170909 23:07:15
Point to remember is that in case both the ends have same value. The greedy user would take the left value by default! 

sanjumsnj:
20170724 05:27:40
Please, some one tell how to use memoization! I could solve the problem recursively! That gave me TLE.


satyabrat35:
20170614 16:50:59
Got 1 WA for full stop :( 

dhrv_shrma04:
20170613 19:40:02
AC in one go! Incomparably happy :D 

heisenberg0820:
20170613 13:40:11
Take care of "If there is a tie, remove the left end" 

prabodh prakash:
20170603 18:55:24
One important note is that  one player is playing with DP strategy and the other player is playing with greedy strategy and then you've to decide the difference of maximum scores that they can make. [as clearly mentioned in the question above  it somehow got skipped in my solution :( ] Last edit: 20170603 18:57:25 

prasoonbatham:
20170524 18:13:15
Very strict tl for java codes! 

da_201501181:
20170521 14:02:18
NOTE: "If there is a tie, remove the left end." caused me 1 WA..


vengatesh15:
20170405 18:00:03
don't forget to consider i.e in greedy approach if both end have same value then take the left end that cost me 2 WA 

nilabja16180:
20170321 19:37:31
DP with RECURSION, AC IN ONE GO! 0.00 sec Last edit: 20170321 19:38:14 
Added by:  Camilo Andrés Varela León 
Date:  20070726 
Time limit:  0.100s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL JSRHINO NODEJS PERL6 VB.NET 
Resource:  East Central North America 2005 