Problem 962
Stone Game III
Hard · 30 pts · Array, Dynamic Programming, Game Theory
Problem
Stones in a row have integer values (possibly negative). Alice and Bob take turns, Alice first; on each turn a player takes 1, 2 or 3 stones from the front of the row. When the row is empty, the player with the larger total wins, or it is a tie. Both play optimally. Print Alice, Bob or Tie. Let diff[i] be the best difference (current player minus opponent) from position i; try taking 1, 2 or 3 stones and subtract the opponent's best difference afterwards.
Input
The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1].
Output
Print Alice, Bob or Tie.
Constraints
1 <= N <= 50000; -1000 <= value <= 1000
Example input
4 1 2 3 7
Example output
Bob
Explanation
For 1 2 3 7, whatever Alice takes, Bob can take the 7 at the end and finish with more points. So the answer is Bob.