Gym - 101972F I'm Bored! 模拟暴力

Being a judge is not always an interesting job! For example, it is very boring to wait for the first submission in the contest. So, judges used to entertain themselves using the "I'm Bored" tab in the PC2 software. In this tab, a button is shown and you need to click it (if you can!).

Since Alaa has been a judge in many contests, the "I'm Bored" tab is also boring to her, so, she decided to play a new game in today's contest. Alaa brings with her a huge bag full of lowercase English letters, and she starts playing with them. Alaa goal is to build a list of palindrome strings of the same length such that each string does not contain the same character more than two times.

After 3 minutes of playing, Alaa wondered what is the longest string's length that she can build? And what is the maximum number of strings the list can contain? When Alaa brings her notebook to calculate the answers, she starts receiving dozens of submissions. So, she gives you her bag and asks you to find the answers for her. Can you?

Input

The first line contains an integer T (1 ≤ T ≤ 104) specifying the number of test cases.

Each test cases consists of a line containing 26 integers f1, ..., f26 (0 ≤ fi ≤ 109), in which fi is how many letters i Alaa has. The letters are numbered from 1 to 26starting from 'a'.

Output

For each test case, print a single line containing two integers x and y, in which xis the length of the strings in the group and y is the size of the group.

Example

Input

2
2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Output

4 1
4 2

Note

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as "madam" or "racecar".

题意:给定一个26个字母的个数,要求能组成最长回文串的长度,与最长长度的个数,回文串中每种字母最多选两个

题解:先判断最多的数量,然后每次模拟着写就行了,最多进行也超不过26次,详见代码解释

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+100;
typedef long long ll;
ll num[27];
int n;
bool cmp(ll x,ll y)
{
	return x>y;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		for(int i=1;i<=26;i++)
			scanf("%lld",&num[i]);
		sort(num+1,num+1+26,cmp);
		ll cnt=0,pos=0; // cnt 选出的最少的字符个数  pos 能选多少个 
		ll ans=0,res=0; // ans 记录最多那多少个 res 可以组成的数量 
		for(int i=1;i<=26;i++)
		{
			if(num[i]<=1)
			{
				ans+=num[i];
				pos=i;
				cnt=num[i];
				break;
			}
			ans+=2;
			pos=i;
			cnt=2;
		}
		if(cnt==0) pos--,cnt=min((ll)2,num[pos]);
		if(ans==0)
		{
			printf("0 0\n");
			continue;
		}
		while(1)
		{
			if(num[pos]<cnt)
			{
				break;
			}
			ll tmp=num[pos]/cnt; //tmp 还能拿出多少个 
			if(pos>1) // 如果前面有,前面肯定至少拿2个 
			{
				if(num[pos-1]<2) break;
				tmp=min(tmp,num[pos-1]/2);
			}
			for(int i=1;i<pos;i++) // 更新 
				num[i]-=tmp*2;
			num[pos]-=tmp*cnt;
			res+=tmp;
			sort(num+1,num+1+26,cmp);
		}
		printf("%lld %lld\n",ans,res);
	}
	return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值