아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Collecting Pancakes

시간 제한30초메모리 제한1024 MB

요약
앨리스와 밥이 번갈아 팬케이크 더미를 차지하되 이미 차지한 더미에 인접한 곳만 고를 수 있고 첫 수의 허용 범위가 다를 때, 최선의 플레이에서 앨리스가 얻는 최대 팬케이크 수를 구한다.
난이도

보통10점 중 7점

유형
그리디, 게임 이론, 구간
정답자
아직 제출이 없습니다

문제

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 11 to N\mathbf{N}. The ii-th stack has exactly A_i\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 L_a\mathbf{L\_a} and R_a\mathbf{R\_a}, inclusive, and claim it. Then, Bob must choose a stack labeled between L_b\mathbf{L\_b} and R_b\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 ii on one of her turns other than the first, she must have claimed either stack i−1i-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 A_1,A_2,…,A_N\mathbf{A\_1}, \mathbf{A\_2}, \dots, \mathbf{A\_N}, where A_i\mathbf{A\_i} denotes the number of pancakes in stack ii.

The third line contains 44 integers L_a\mathbf{L\_a}, R_a\mathbf{R\_a}, L_b\mathbf{L\_b}, and R_b\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 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.

제한

  • 1≤T≤1001 \le \mathbf{T} \le 100.
  • 1≤A_i≤1091 \le \mathbf{A\_i} \le 10^9, for all ii.
  • 1≤L_a≤R_a≤N1 \le \mathbf{L\_a} \le \mathbf{R\_a} \le \mathbf{N}
  • 1≤L_b≤R_b≤N1 \le \mathbf{L\_b} \le \mathbf{R\_b} \le \mathbf{N}
  • It is not the case that L_a≤L_b=R_b≤R_a\mathbf{L\_a} \le \mathbf{L\_b} = \mathbf{R\_b} \le \mathbf{R\_a}. (Bob is guaranteed to be able to pick a stack for his first turn regardless of Alice's choice.)

힌트

In Sample Case #1, there are 55 pancake stacks with 30,50,40,20,1030, 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 22, then Bob claims stack 44.
  2. Alice claims stack 33 in her second turn, then Bob claims stack 55 in his second turn.
  3. Alice claims stack 11 in her third turn, then the game ends because all stacks have been claimed.

At the end of the game, Alice claimed stacks 1,21, 2, and 33 and Bob claimed stacks 44 and 55. 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 33, then Bob claims stack 22.
  2. Alice claims stack 44 in her second turn, then Bob claims stack 11 in his second turn.
  3. Alice claims stack 55 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 11 is more valuable than everything else combined, Alice claims it before Bob does. Then, Bob can claim stack 22, making Alice have to skip all her subsequent turns. Alice still finishes with 9090 pancakes and Bob with just 3030.

예제1

  1. 예제 1

    입력
    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