codeforces-1399C-Boats Competition

1 篇文章 0 订阅
1 篇文章 0 订阅

C. Boats Competition

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn people who want to participate in a boat competition. The weight of the ii-th participant is wiwi. 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 kk teams (a1,b1)(a1,b1), (a2,b2)(a2,b2), ……, (ak,bk)(ak,bk), where aiai is the weight of the first participant of the ii-th team and bibi is the weight of the second participant of the ii-th team, then the condition a1+b1=a2+b2=⋯=ak+bk=sa1+b1=a2+b2=⋯=ak+bk=s, where ss is the total weight of each team, should be satisfied.

Your task is to choose such ss 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 tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Then tt test cases follow.

The first line of the test case contains one integer nn (1≤n≤501≤n≤50) — the number of participants. The second line of the test case contains nn integers w1,w2,…,wnw1,w2,…,wn (1≤wi≤n1≤wi≤n), where wiwi is the weight of the ii-th participant.

Output

For each test case, print one integer kk: the maximum number of teams people can compose with the total weight ss, if you choose ss optimally.

Example

input

Copy

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

output

Copy

2
3
4
1
2

Note

In the first test case of the example, we can reach the optimal answer for s=6s=6. Then the first boat is used by participants 11 and 55 and the second boat is used by participants 22 and 44 (indices are the same as weights).

In the second test case of the example, we can reach the optimal answer for s=12s=12. Then first 66 participants can form 33 pairs.

In the third test case of the example, we can reach the optimal answer for s=3s=3. The answer is 44 because we have 44 participants with weight 11 and 44 participants with weight 22.

In the fourth test case of the example, we can reach the optimal answer for s=4s=4 or s=6s=6.

In the fifth test case of the example, we can reach the optimal answer for s=3s=3. Note that participant with weight 33 can't use the boat because there is no suitable pair for him in the list.

题意:从一堆人中选一些人出来组成队伍比赛划艇,每个队伍两个人,每个人的总量是wi,要求每个队伍的总重量相同。问最多能选出多少个队伍。

思路:由于题目的数据范围比较小,直接暴力,枚举所有可能的总重量 i ,对于每个总量计算出能选出的队伍数,保存能选出最多的队伍数就是答案。在计算队伍数的时候,先根据总量对每个人进行排序,用两个指针left,right分别指向重量数组的头和尾,每次相加w[left]和w[right],如果等于当前总重量,则答案+1,最后选出最大的答案输出即可。

 

#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#define MAXN 1000000005
using namespace std;
bool cmp(int a,int b){
	return a<b;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int num[55];
		for(int i=0;i<n;i++){
			cin>>num[i];
		}
		sort(num,num+n,cmp);
		int tmp;
		int ans=0;
		for(int i=2;i<=2*n;i++){
			tmp=0;
			int left=0;
			int right=n-1;
			while(left<right){
				if(num[left]+num[right]==i){
					tmp++;
					left++;
					right--;
				}
				else if(num[left]+num[right]<i)left++;
				else {
					right--;
				}
			}
			if(tmp>ans)ans=tmp;
		}
		cout<<ans<<endl;
	}
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值