Logo
(追記) (追記ここまで)

33059번 - Cake Game 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB25914213359.910%

문제

Bessie and Elsie have discovered a row of $N$ cakes $(2 \leq N \leq 5\cdot 10^5, N \text{ even})$ cakes, with sizes $a_1,a_2,\dots,a_N$ in that order (1ドル\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:

  1. Bessie chooses two adjacent cakes and stacks them, creating a new cake with the sum of the sizes.
  2. 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 $T$ (1ドル\le T\le 10$) independent test cases. It is guaranteed that the sum of all $N$ within an input does not exceed 10ドル^6$.

Each test case is formatted as follows. The first line contains $N$. The next line contains $N$ space-separated integers, $a_1,a_2,\ldots,a_N$.

출력

For each test case, output a line containing $b$ and $e,ドル 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

힌트

For the first test case, under optimal play,

  1. Bessie will stack the middle two cakes. The cakes now have sizes $[40,50,10]$.
  2. Elsie will eat the leftmost cake. The remaining cakes now have sizes $[50,10]$.
  3. Bessie stacks the remaining two cakes.

Bessie will eat 30ドル+20+10=60$ cake, while Elsie will eat 40ドル$ cake.

The second test case is the reverse of the first, so the answer is the same.

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2024 December Contest > Silver 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /