#P12951. [GCJ Farewell Round #2] Collecting Pancakes

    ID: 12753 Type: RemoteJudge 30000ms 2048MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>贪心2023前缀和Google Code Jam

[GCJ Farewell Round #2] Collecting Pancakes

题目描述

Alice and Bob both have a sweet tooth, and they are going to play a game to collect pancakes. There are N\mathbf{N} pancake stacks lined up on the table labeled from 1 to N\mathbf{N}. The ii-th stack has exactly Ai\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 La\mathbf{L}_{\mathrm{a}} and Ra\mathbf{R}_{\mathrm{a}}, inclusive, and claim it. Then, Bob must choose a stack labeled between Lb\mathbf{L}_{\mathrm{b}} and Rb\mathbf{R}_{\mathrm{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 ii on one of her turns other than the first, she must have claimed either stack i1i-1 or stack i+1i+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, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case consists of three lines.

The first line of each test case contains an integer N\mathbf{N}, representing the number of pancake stacks.

The second line contains N\mathbf{N} integers $\mathbf{A}_{1}, \mathbf{A}_{2}, \ldots, \mathbf{A}_{\mathbf{N}}$, where Ai\mathbf{A}_{i} denotes the number of pancakes in stack ii.

The third line contains 4 integers $\mathbf{L}_{\mathrm{a}}, \mathbf{R}_{\mathrm{a}}, \mathbf{L}_{\mathrm{b}}$, and Rb\mathbf{R}_{\mathrm{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 xx is the test case number (starting from 1) and yy 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

提示

Sample Explanation

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:

  1. At the beginning, Alice claims stack 2, then Bob claims stack 4.
  2. Alice claims stack 3 in her second turn, then Bob claims stack 5 in his second turn.
  3. Alice claims stack 1 in her third turn, then the game ends because all stacks have been claimed.

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=12030 + 50 + 40 = 120.

In Sample Case #2, one way of optimal play is:

  1. At the beginning, Alice claims stack 3, then Bob claims stack 2.
  2. Alice claims stack 4 in her second turn, then Bob claims stack 1 in his second turn.
  3. Alice claims stack 5 in her third turn, then the game ends because all stacks have been claimed.

The number of pancakes Alice collects is 80+10+10=10080 + 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.

Limits

  • 1T1001 \leq \mathbf{T} \leq 100.
  • 1Ai1091 \leq \mathbf{A}_{i} \leq 10^{9}, for all ii.
  • $1 \leq \mathbf{L}_{\mathrm{a}} \leq \mathbf{R}_{\mathrm{a}} \leq \mathbf{N}$
  • $1 \leq \mathbf{L}_{\mathrm{b}} \leq \mathbf{R}_{\mathrm{b}} \leq \mathbf{N}$
  • It is not the case that $\mathbf{L}_{\mathrm{a}} \leq \mathbf{L}_{\mathrm{b}}=\mathbf{R}_{\mathrm{b}} \leq \mathbf{R}_{\mathrm{a}}$. (Bob is guaranteed to be able to pick a stack for his first turn regardless of Alice's choice.)

Test Set 1 (4 Pts, Visible Verdict)

  • 2N1002 \leq \mathbf{N} \leq 100.

Test Set 2 (10 Pts, Visible Verdict)

  • 2N1052 \leq \mathbf{N} \leq 10^{5}.