RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0630

Cake Game

Gold II 골드 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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?

Problem credits: Linda Zhao, Agastya Goel, Gavin Ye

제약

SCORING

  • Input 2: All \(a_i\) are equal.
  • Input 3: \(N\le 10\)
  • Inputs 4-7: \(N\le 5000\)
  • Inputs 8-11: No additional constraints.

Problem credits: Linda Zhao, Agastya Goel, Gavin Ye

입력 형식

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
출력
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.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > December > Silver

태그

평가 및 의견

Cake Game

개요
출제자 난이도 Gold II 골드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Cake Game

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8