| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 30 초 (추가 시간 없음) | 1024 MB | 21 | 13 | 12 | 60.000% |
Alice and Bob both have a sweet tooth, and they are going to play a game to collect pancakes. There are $\mathbf{N}$ pancake stacks lined up on the table labeled from 1ドル$ to $\mathbf{N}$. The $i$-th stack has exactly $\mathbf{A_i}$ pancakes. Alice and Bob are going to collect pancakes by alternating turns claiming full stacks. For the first turn, Alice must choose a stack labeled between $\mathbf{L_a}$ and $\mathbf{R_a},ドル inclusive, and claim it. Then, Bob must choose a stack labeled between $\mathbf{L_b}$ and $\mathbf{R_b},ドル inclusive, and different from the one chosen by Alice, and claim it.
In subsequent turns, each of them must choose an unclaimed stack that is adjacent to a stack they claimed themselves before. That is, for Alice to claim stack $i$ on one of her turns other than the first, she must have claimed either stack $i-1$ or stack $i+1$ in one of her previous turns. The same is true for Bob. If at some point there is no valid choice for either player, they skip that turn and claim no stack.
The game ends when every stack is claimed. At that point, Alice collects all pancakes from all stacks she claimed, and Bob collects all pancakes in all stacks he claimed.
Alice wants to get as many pancakes as possible for herself, and Bob wants to get as many pancakes as possible for himself. Can you help Alice find out the maximum number of pancakes she can collect if they both play optimally?
The first line of the input gives the number of test cases, $\mathbf{T}$. $\mathbf{T}$ test cases follow. Each test case consists of three lines.
The first line of each test case contains an integer $\mathbf{N},ドル representing the number of pancake stacks.
The second line contains $\mathbf{N}$ integers $\mathbf{A_1}, \mathbf{A_2}, \dots, \mathbf{A_N},ドル where $\mathbf{A_i}$ denotes the number of pancakes in stack $i$.
The third line contains 4ドル$ integers $\mathbf{L_a},ドル $\mathbf{R_a},ドル $\mathbf{L_b},ドル and $\mathbf{R_b},ドル the inclusive ranges of pancake stack labels Alice and Bob can choose for their first turn, respectively.
For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the maximum number of pancakes Alice can collect after playing the game optimally.
3 5 30 50 40 20 10 1 2 4 5 5 20 20 80 10 10 1 4 2 5 4 90 10 10 10 1 4 1 4
Case #1: 120 Case #2: 100 Case #3: 90
In Sample Case #1, there are 5ドル$ pancake stacks with 30,ドル 50, 40, 20, 10$ pancakes in them. Alice can choose the first or second stack at the beginning of the game, and Bob can choose the fourth or fifth stack to begin with. One way in which they both play optimally is:
At the end of the game, Alice claimed stacks 1,ドル 2,ドル and 3ドル$ and Bob claimed stacks 4ドル$ and 5ドル$. The number of pancakes Alice collects is 30ドル+50+40=120$.
In Sample Case #2, one way of optimal play is:
The number of pancakes Alice collects is 80ドル+10+10=100$.
In Sample Case #3, both can claim any stack in their first turn. Since stack 1ドル$ is more valuable than everything else combined, Alice claims it before Bob does. Then, Bob can claim stack 2ドル,ドル making Alice have to skip all her subsequent turns. Alice still finishes with 90ドル$ pancakes and Bob with just 30ドル$.
Contest > Google > Code Jam > Google Code Jam Farewell Round > Round B A번