1749C.md (1565B)
1 Source: https://codeforces.com/problemset/problem/1749/C 2 3 C. Number Game 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Alice and Bob are playing a game. They have an array of positive integers $a$ of size $n$. 22 23 Before starting the game, Alice chooses an integer $k \ge 0$. The game lasts for $k$ stages, the stages are numbered from $1$ to $k$. During the $i$-th stage, Alice must remove an element from the array that is less than or equal to $k - i + 1$. After that, if the array is not empty, Bob must add $k - i + 1$ to an arbitrary element of the array. Note that both Alice's move and Bob's move are two parts of the same stage of the game. If Alice can't delete an element during some stage, she loses. If the $k$-th stage ends and Alice hasn't lost yet, she wins. 24 25 Your task is to determine the maximum value of $k$ such that Alice can win if both players play optimally. Bob plays against Alice, so he tries to make her lose the game, if it's possible. 26 27 Input 28 29 The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. 30 31 The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — the size of the array $a$. 32 33 The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$). 34 35 Output 36 37 For each test case, print one integer — the maximum value of $k$ such that Alice can win if both players play optimally. 38 39 Example 40 41 Input 42 43 ``` 44 4 45 46 3 47 48 1 1 2 49 50 4 51 52 4 4 4 4 53 54 1 55 56 1 57 58 5 59 60 1 3 2 1 1 61 ``` 62 63 Output 64 65 ``` 66 2 67 0 68 1 69 3 70 ```