#693
Unrated
Cake Game
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie and Elsie have discovered a row of NN cakes (2N5105,N even)(2 \leq N \leq 5\cdot 10^5, N \text{ even}) cakes, with sizes a1,a2,,aNa_1,a_2,\dots,a_N in that order (1ai1091\le a_i\le 10^9).

Each cow wants to eat as much as possible. However, being very civilized cows, they decided to play a game to split it! The game proceeds with both cows alternating turns. Each turn consists of one of the following:

Bessie chooses two adjacent cakes and stacks them, creating a new cake with the sum of the sizes.Elsie chooses either the leftmost or rightmost cake and puts it in her stash.

When only one cake remains, Bessie eats it, and Elsie eats all cakes in her stash. If both cows play optimally to maximize the amount of cake they eat and Bessie plays first, how much cake will each cow eat?

입력

Each input consists of TT (1T101\le T\le 10) independent test cases. It is guaranteed that the sum of all NN within an input does not exceed 10610^6.

Each test case is formatted as follows. The first line contains NN. The next line contains NN space-separated integers, a1,a2,,aNa_1,a_2,\ldots,a_N.

출력

For each test case, output a line containing bb and ee, representing the amounts of cake Bessie and Elsie respectively will consume if both cows play optimally.

예제 입력 1

2
4
40 30 20 10
4
10 20 30 40

예제 출력 1

60 40
60 40

점수

Input 2: All aia_i are equal.Input 3: N10N\le 10Inputs 4-7: N5000N\le 5000Inputs 8-11: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.