問題一覧 > 通常問題

No.2835 Take and Flip

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 194
作問者 : milkcoffee / テスター : first_vil ygussany
お気に入りにしたユーザー ProblemId : 9038 / 自分の提出
問題文最終更新日: 2024-08-03 20:23:18
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. Show the original
yukicoder contest 440 (順位表) の他の問題:

Problem Statement

There are $N$ integers. The $i$-th integer is $A_i$. $\mathrm{First}$ and $\mathrm{Second}$ take turns performing the following operation, $1$ time per turn.

  • Choose $1$ integer and delete it. Then, multiply all the remaining integers by $-1$.

$\mathrm{First}$ moves first, and the game ends when all the integers have been deleted.

Let $X$ be the sum of the integers deleted by $\mathrm{First}$, and $Y$ be the sum of the integers deleted by $\mathrm{Second}$. $\mathrm{First}$ wants to maximize $X-Y$, while $\mathrm{Second}$ wants to minimize $X-Y$.

Find the final value of $X-Y$ when both players play optimally.

Input

$N$
$A_1$ $A_2$ $\cdots$ $A_N$

  • $1 \leq N \leq 2 \times 10^5$
  • $|A_i| \leq 10^9$ $(1 \leq i \leq N)$
  • All input values are integers.

Output

Output the final value of $X-Y$ when both players play optimally, as an integer.

Sample

Sample 1
Input
3
-1 4 -2
Output
1

First, $\mathrm{First}$ chooses and deletes $4$, then multiplies the remaining integers by $-1$. The remaining integers become $1,2$.

Next, $\mathrm{Second}$ chooses and deletes $2$, then multiplies the remaining integers by $-1$. The remaining integer is $-1$.

Finally, $\mathrm{First}$ chooses and deletes $-1$. No integers remain.

Since $X=4 + (-1) = 3$ , $Y=2$, we have $X-Y = 1$.

Sample 2
Input
14
-523328364 -409607197 -712671537 -766381325 472867409 -811025573 -971818355 -66399298 633965694 -22544287 -720923839 -905888279 514666353 -359356404
Output
-4648445002

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