CF1399C.Boats Competition
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n people who want to participate in a boat competition. The weight of the i-th participant is wi. 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.
So, if there are k teams (a1,b1), (a2,b2), …, (ak,bk), where ai is the weight of the first participant of the i-th team and bi is the weight of the second participant of the i-th team, then the condition a1+b1=a2+b2=⋯=ak+bk=s, where s is the total weight of each team, should be satisfied.
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.
You have to answer t independent test cases.
有 n 个人希望参加划船比赛。第 i 个人的体重为 wi。本比赛仅允许由两人组成的队伍参赛。作为组织者,你认为只有总重量相等的队伍参赛才显得公平。
因此,若共有 k 支队伍 (a1,b1)、(a2,b2)、…、(ak,bk),其中 ai 表示第 i 支队伍中第一名队员的体重,bi 表示第 i 支队伍中第二名队员的体重,则需满足条件:
a1+b1=a2+b2=⋯=ak+bk=s,
其中 s 是每支队伍的总重量。
你的任务是选择一个合适的 s,使得能够组成的队伍数量达到最大。注意:每位参与者至多只能属于一支队伍。
你需要回答 t 个相互独立的测试用例。
输入格式
The first line of the input contains one integer t (1≤t≤1000) — the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1≤n≤50) — the number of participants. The second line of the test case contains n integers w1,w2,…,wn (1≤wi≤n), where wi is the weight of the i-th participant.
输入的第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含一个整数 n(1≤n≤50),表示参与者的数量。每个测试用例的第二行包含 n 个整数 w1,w2,…,wn(1≤wi≤n),其中 wi 表示第 i 个参与者的体重。
输出格式
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.
对于每个测试用例,输出一个整数 k:在最优选择总重量 s 的前提下,人们最多能组成的队伍数量。
输入输出样例
输入#1
5 5 1 2 3 4 5 8 6 6 6 6 6 6 8 8 8 1 2 2 1 2 1 1 2 3 1 3 3 6 1 1 3 4 2 2
输出#1
2 3 4 1 2
说明/提示
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).
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.
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.
In the fourth test case of the example, we can reach the optimal answer for s=4 or s=6.
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.
在示例的第一个测试用例中,当 s=6 时可达到最优解。此时,第一艘船由参与者 1 和 5 共同使用,第二艘船由参与者 2 和 4 共同使用(下标与重量相同)。
在示例的第二个测试用例中,当 s=12 时可达到最优解。此时前 6 名参与者可以组成 3 对。
在示例的第三个测试用例中,当 s=3 时可达到最优解。答案为 4,因为我们有 4 名重量为 1 的参与者和 4 名重量为 2 的参与者。
在示例的第四个测试用例中,当 s=4 或 s=6 时可达到最优解。
在示例的第五个测试用例中,当 s=3 时可达到最优解。注意:重量为 3 的参与者无法使用船只,因为列表中没有适合与他配对的参与者。
输入解题思路,AI测评打分。不知道怎么写?