1399C.md (2562B)
1 Source: https://codeforces.com/problemset/problem/1399/C 2 3 C. Boats Competition 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 There are $n$ people who want to participate in a boat competition. The weight of the $i$-th participant is $w_i$. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with the same total weight. 22 23 So, if there are $k$ teams $(a_1, b_1)$, $(a_2, b_2)$, $\dots$, $(a_k, b_k)$, where $a_i$ is the weight of the first participant of the $i$-th team and $b_i$ is the weight of the second participant of the $i$-th team, then the condition $a_1 + b_1 = a_2 + b_2 = \dots = a_k + b_k = s$, where $s$ is the total weight of each team, should be satisfied. 24 25 Your task is to choose such $s$ that the number of teams people can create is the maximum possible. Note that each participant can be in no more than one team. 26 27 You have to answer $t$ independent test cases. 28 29 Input 30 31 The first line of the input contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow. 32 33 The first line of the test case contains one integer $n$ ($1 \le n \le 50$) — the number of participants. The second line of the test case contains $n$ integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le n$), where $w_i$ is the weight of the $i$-th participant. 34 35 Output 36 37 For each test case, print one integer $k$: the maximum number of teams people can compose with the total weight $s$, if you choose $s$ optimally. 38 39 Example 40 41 Input 42 43 ``` 44 5 45 5 46 1 2 3 4 5 47 8 48 6 6 6 6 6 6 8 8 49 8 50 1 2 2 1 2 1 1 2 51 3 52 1 3 3 53 6 54 1 1 3 4 2 2 55 ``` 56 57 Output 58 59 ``` 60 2 61 3 62 4 63 1 64 2 65 ``` 66 67 Note 68 69 In the first test case of the example, we can reach the optimal answer for $s=6$. Then the first boat is used by participants $1$ and $5$ and the second boat is used by participants $2$ and $4$ (indices are the same as weights). 70 71 In the second test case of the example, we can reach the optimal answer for $s=12$. Then first $6$ participants can form $3$ pairs. 72 73 In the third test case of the example, we can reach the optimal answer for $s=3$. The answer is $4$ because we have $4$ participants with weight $1$ and $4$ participants with weight $2$. 74 75 In the fourth test case of the example, we can reach the optimal answer for $s=4$ or $s=6$. 76 77 In the fifth test case of the example, we can reach the optimal answer for $s=3$. Note that participant with weight $3$ can't use the boat because there is no suitable pair for him in the list.