問題一覧 > 通常問題

No.1150 Cream Puff Game (Easy)

レベル : / AI推定難易度 : 1600 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 137
作問者 : Kiri8128 / テスター : tpyneriver
お気に入りにしたユーザー ProblemId : 4649 / 自分の提出
問題文最終更新日: 2020-08-08 16:02:29
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 260 (Typical Game Contest) (順位表) の他の問題:

Problem Statement

315-san and 8128-san love cream puffs, so the two of them are going to play the cream puff game.
The cream puff game is played using vertices arranged in a circle. There are $N$ vertices, numbered from $1$ to $N$. Vertex $i\ (1 \le i \le N - 1)$ and vertex $i+1$ are adjacent. Vertex $N$ and vertex $1$ are also adjacent. No other pairs of vertices are adjacent. On vertex $i\ (1 \le i \le N)$, $A_i$ cream puffs are placed. Initially, no vertex is occupied.

The game proceeds as follows.

First, 315-san occupies vertex $s$ and eats all the cream puffs placed there. Then, 8128-san occupies vertex $t$ and eats all the cream puffs placed there.
Next, starting with 315-san, the two players alternately perform the following operation until every vertex is occupied by one of them.

  • Choose one vertex that is not yet occupied by either player and is adjacent to a vertex occupied by the player, and occupy it
  • Eat all the cream puffs placed on the vertex just occupied
Let $X$ be the number of cream puffs 315-san has eaten in the end, and $Y$ be the number of cream puffs 8128-san has eaten in the end. 315-san wants to maximize $X-Y$, while 8128-san wants to minimize $X-Y$. What is the value of $X-Y$ when both players play optimally?

Input

$N$
$s\ t$
$A_1\ A_2\ \cdots A_N$

$4\le N\le 10^5$
$1\le s,\ t\le N$
$s\neq t$
$1\le A_i\le 10^9\ (1\le i\le N)$
All inputs are integers.

Output

Output the answer on one line. Print a newline at the end.

Sample

Sample 1
Input
4
1 3
10 20 50 100
Output
40

First, 315-san eats the 10 cream puffs on vertex 1, and 8128-san eats the 50 cream puffs on vertex 3.
Next, 315-san must choose one of vertex 2, which has 20 cream puffs, and vertex 4, which has 100 cream puffs; choosing vertex 4 is optimal.
On 8128-san's following turn, the only choice is vertex 2.
315-san has eaten $10 + 100 = 110$ cream puffs and 8128-san has eaten $50 + 20 = 70$ cream puffs, so output $40\ (=110-70)$.

Sample 2
Input
7
1 7
10 20 30 40 50 60 70
Output
-80

There are 7 vertices. Initially, 315-san occupies vertex 1 and 8128-san occupies vertex 7.
After that, each player has only one vertex to choose from on each turn. 315-san occupies vertices 2, 3, 4 and 8128-san occupies vertices 6, 5, in that order.
315-san has eaten $10+20+30+40 = 100$ cream puffs and 8128-san has eaten $70+60+50 = 180$ cream puffs, so output $-80\ (=100-180)$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。