EPIC Institute of Technology Round Summer 2024 (Div. 1 + Div. 2)
D
World is Mine
Codeforces
1800
原题
← CE →
翻译中…

Alice and Bob are playing a game. Initially, there are $n$ cakes, with the $i$-th cake having a tastiness value of $a_i$.

翻译中…

Alice and Bob take turns eating them, with Alice starting first:

翻译中…
  • In her turn, Alice chooses and eats any remaining cake whose tastiness is strictly greater than the maximum tastiness of any of the cakes she's eaten before that. Note that on the first turn, she can choose any cake.
  • In his turn, Bob chooses any remaining cake and eats it.
翻译中…

The game ends when the current player can't eat a suitable cake. Let $x$ be the number of cakes that Alice ate. Then, Alice wants to maximize $x$, while Bob wants to minimize $x$.

翻译中…

Find out how many cakes Alice will eat if both players play optimally.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 500$) — 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 \le n \le 5000$) — the number of cakes.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the tastiness values of the cakes.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of cakes Alice will eat if both players play optimally.

翻译中…

Note

翻译中…

In the first test case, one possible sequence of turns is:

翻译中…
  1. Alice eats a cake with a tastiness value of $1$. The remaining cakes are $[4, 2, 3]$.
  2. Bob eats a cake with a tastiness value of $2$. The remaining cakes are $[4, 3]$.
  3. Alice eats a cake with a tastiness of $3$. The remaining cakes are $[4]$.
  4. Bob eats a cake with a tastiness value of $4$. The remaining cakes are $[]$.
  5. Since there are no more cakes left, the game ends.
翻译中…

In the second test case, one possible sequence of turns is:

翻译中…
  1. Alice eats a cake with a tastiness value of $1$. The remaining cakes are $[1, 1]$.
  2. Bob eats a cake with a tastiness value of $1$. The remaining cakes are $[1]$.
  3. Since Alice has already eaten a cake with a tastiness value of $1$, she cannot make a turn, so the game ends.
翻译中…

样例

Input #1
9
4
1 4 2 3
3
1 1 1
5
1 4 2 3 4
4
3 4 1 4
1
1
8
4 3 2 5 6 8 3 4
7
6 1 1 3 5 3 1
11
6 11 6 8 7 5 3 11 2 3 5
17
2 6 5 3 9 1 6 2 5 6 3 2 3 9 6 1 6
Output #1
2
1
3
2
1
3
2
4
4
InputCopy OutputCopy
题目信息
题号
1987D
时间限制
2 s
内存限制
256 MB
标签
动态规划
博弈论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。