No.1906 Twinkle Town
タグ : / 解いたユーザー数 17
作問者 : 👑
hitonanode
/ テスター :
Sumitacchan
Problem Statement
In a certain town, there are $10^9$ street lamps and $N$ magic wands used to turn these street lamps on and off. Initially, all street lamps are off. Each wand $i$ ($1 \le i \le N$) has a fixed value $A_i$ called its power.
Denshoku Taro and Setsuden Jiro play a game using these wands. The two take turns choosing one wand at a time, and the player who chose it immediately waves it. Denshoku Taro goes first. When either of the two waves a wand, it has the following effect.
- When Denshoku Taro waves a wand of power $A$, street lamps $1, \dots, A$ become on (regardless of their previous state).
- When Setsuden Jiro waves a wand of power $A$, street lamps $1, \dots, A$ become off (regardless of their previous state).
Denshoku Taro aims to maximize the score and Setsuden Jiro aims to minimize the score, and both always follow an optimal strategy (both players also know all information, including each other's goals). Find the score at the point when the two have finished waving all the wands. You are given $T$ test cases; solve each of them.
Input
The first line contains the number of test cases in the input.
$T$
The test cases are then given over the following $2T$ lines. Each test case is given over 2 lines in the following format.
$N$ $A_1 \ A_2 \ \dots A_N$
- $1 \le T \le 2 \times 10^4$
- $1 \le N \le 2 \times 10^5$
- $1 \le A_i \le 10^9$ $(1 \le i \le N)$
- The sum of the $T$ values of $N$ in a single input is at most $2 \times 10^5$
- All input values are integers
Output
Output $T$ lines. On the $i$-th line $(1 \le i \le T)$, output an integer that is the answer to the $i$-th test case. Also print a newline at the end of the $T$-th line.
Sample
Sample 1
Input
1 3 3 4 6
Output
5
If Denshoku Taro first waves the wand of power $6$, street lamps $1, 2, 3, 4, 5, 6$ become on. If Setsuden Jiro then waves the wand of power $4$ on the second move, only street lamps $5, 6$ remain on. Finally, Denshoku Taro waves the wand of power $3$, and the $5$ street lamps $1, 2, 3, 5, 6$ are on.
It can be verified that if either player tries to play differently from the above, the game result is always worse for that player than the above result (as the opponent chooses optimal moves). Therefore, $5$ is output as the result when both players act optimally.
Sample 2
Input
1 3 3 5 6
Output
5
Sample 3
Input
4 1 8 2 10 4 4 3 5 1 7 5 6 7 8 3 9
Output
8 6 4 7
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。