Hocolate Hame
시간 제한2초메모리 제한2048 MB
두 사람이 양 끝에서 번갈아 조각을 먹는다. 처음에는 1개 또는 2개를 먹고, 그다음부터는 직전에 먹은 개수 k 또는 k+1개를 먹는다. 둘 다 자신이 먹은 단맛 총합에서 상대의 총합을 뺀 값을 최대화하도록 최선으로 두며, 최종 차이를 출력한다.
문제
Azizkhan and Temirulan love Swiss chocolate. Recently they bought a chocolate bar which is a row of pieces. Each piece has a certain amount of sweetness. Moreover, the sweetness of a piece can be negative.
To divide the chocolate bar in a fair way, they devised some rules for eating the pieces:
- The pieces are numbered from left to right.
- Azizkhan will eat the chocolate bar from the left side, and Temirulan from the right side.
- Azizkhan and Temirulan will eat the chocolate in turns.
- Each player eats one or more pieces in his turn.
- Azizkhan eats first, and can eat either or pieces.
- If pieces were eaten on the previous move, then the current player should eat either or pieces.
- They stop eating if it is impossible to make the next move.
Azizkhan and Temirulan are both competitive persons. Each of them wants to consume more sweetness than the other. In other words, each player tries to maximize the difference between the total sweetness of the pieces he ate himself and the total sweetness of the pieces eaten by the opponent. Help them to find the difference between the total sweetness consumed by Azizkhan and Temirulan if both players are super-puper-monstro-smart-optimal persons.
입력
The first line contains an integer (): the number of pieces in the chocolate bar.
The second line contains integers (): the sweetness values of the pieces.
출력
Output a line with a single integer: the difference between the total sweetness consumed by Azizkhan and the total sweetness consumed by Temirulan (in this order) if both play optimally.