311069: CF1930A. Maximise The Score

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Maximise The Scoretime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

There are $2n$ positive integers written on a whiteboard. Being bored, you decided to play a one-player game with the numbers on the whiteboard.

You start with a score of $0$. You will increase your score by performing the following move exactly $n$ times:

  • Choose two integers $x$ and $y$ that are written on the whiteboard.
  • Add $\min(x,y)$ to your score.
  • Erase $x$ and $y$ from the whiteboard.

Note that after performing the move $n$ times, there will be no more integers written on the whiteboard.

Find the maximum final score you can achieve if you optimally perform the $n$ moves.

Input

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 5000$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 50$) — the number of integers written on the whiteboard is $2n$.

The second line of each test case contains $2n$ integers $a_1,a_2,\ldots,a_{2n}$ ($1 \leq a_i \leq 10^7$) — the numbers written on the whiteboard.

Output

For each test case, output the maximum final score that you can achieve.

ExampleInput
3
1
2 3
2
1 1 2 1
3
1 1 1 1 1 1
Output
2
2
3
Note

In the first test case, you can only make one move. You select $x=2$ and $y=3$, and your score will be $\min(x,y)=2$.

In the second test case, the following is a sequence of moves that achieves a final score of $2$:

  • In the first move, select $x=1$ and $y=1$. Then, add $\min(x,y)=1$ to the score. After erasing $x$ and $y$, the integers left on the whiteboard are $1$ and $2$.
  • In the second move, select $x=1$ and $y=2$. Then, add $\min(x,y)=1$ to the score. After removing $x$ and $y$, no more integers will be left on the whiteboard.
It can be proved that it is not possible to get a score greater than $2$.

In the third test case, you will perform the move thrice, adding $1$ to the score each time.

Output

题目大意:最大化得分

有一个白板上有2n个正整数,你可以玩一个单人游戏,游戏开始时得分为0。在游戏中,你需要做恰好n次操作,每次操作如下:

1. 在白板上选择两个整数x和y。
2. 将min(x,y)加到你的得分上。
3. 将x和y从白板上擦除。

在进行了n次操作之后,白板上将不再有整数。求你最终能获得的最大得分。

输入数据格式:
- 输入包含多个测试用例,第一行是一个整数t(1≤t≤5000),表示测试用例的数量。
- 每个测试用例的第一行是一个整数n(1≤n≤50),表示白板上的整数数量是2n。
- 每个测试用例的第二行包含2n个整数a_1,a_2,…,a_2n(1≤a_i≤10^7),表示白板上的数字。

输出数据格式:
- 对于每个测试用例,输出你能获得的最大最终得分。

示例:
```
输入
3
1
2 3
2
1 1 2 1
3
1 1 1 1 1 1

输出
2
2
3
```

注意:
- 在第一个测试用例中,只能进行一次操作。选择x=2和y=3,得分为min(x,y)=2。
- 在第二个测试用例中,可以通过选择x=1和y=1,然后选择x=1和y=2,最终得分为2。
- 在第三个测试用例中,每次操作都可以选择两个1,从而得分为3。题目大意:最大化得分 有一个白板上有2n个正整数,你可以玩一个单人游戏,游戏开始时得分为0。在游戏中,你需要做恰好n次操作,每次操作如下: 1. 在白板上选择两个整数x和y。 2. 将min(x,y)加到你的得分上。 3. 将x和y从白板上擦除。 在进行了n次操作之后,白板上将不再有整数。求你最终能获得的最大得分。 输入数据格式: - 输入包含多个测试用例,第一行是一个整数t(1≤t≤5000),表示测试用例的数量。 - 每个测试用例的第一行是一个整数n(1≤n≤50),表示白板上的整数数量是2n。 - 每个测试用例的第二行包含2n个整数a_1,a_2,…,a_2n(1≤a_i≤10^7),表示白板上的数字。 输出数据格式: - 对于每个测试用例,输出你能获得的最大最终得分。 示例: ``` 输入 3 1 2 3 2 1 1 2 1 3 1 1 1 1 1 1 输出 2 2 3 ``` 注意: - 在第一个测试用例中,只能进行一次操作。选择x=2和y=3,得分为min(x,y)=2。 - 在第二个测试用例中,可以通过选择x=1和y=1,然后选择x=1和y=2,最终得分为2。 - 在第三个测试用例中,每次操作都可以选择两个1,从而得分为3。

加入题单

上一题 下一题 算法标签: