No.1150 Cream Puff Game (Easy)
タグ : / 解いたユーザー数 137
作問者 :
Kiri8128
/ テスター :
tpyneriver
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
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もしくは右上の雲マークをクリックしてアカウントを作成してください。