H. Happy Birthday

194 篇文章 1 订阅
44 篇文章 0 订阅
该问题要求找出一组生日蜡烛(每个代表0-9之间的数字)中,第一次无法组合成猫年龄的情况。给定每种数字蜡烛的数量,需要找到最小的数,这个数之前的数都能用蜡烛组合出来,但这个数不行。输出这个最小的数。
摘要由CSDN通过智能技术生成

链接:https://codeforces.com/problemset/problem/1250/H

You have a set of birthday cake candles. Each of such candles represents a digit between 00 and 99, inclusive.

Example of birthday cake candles.

Let's denote the candle representing the digit dd as dd-candle.

Your set contains c0c0 instances of 00-candles, c1c1 instances of 11-candles and so on. So, the total number of candles is c0+c1+⋯+c9c0+c1+⋯+c9.

These digits are needed to wish your cat a happy birthday. For each birthday, starting with the first, you want to compose the age of the cat using the digits from the set.

Since you light candles for a very short time, candles don't have time to burn out. For this reason you can reuse candles an arbitrary number of times (therefore your set of candles never changes).

For example, if you have one instance of each digit (i.e. c0=c1=⋯=c9=1c0=c1=⋯=c9=1), you can compose any number from 11 to 1010 using this set, but you cannot compose 1111.

You have to determine the first birthday, on which you cannot compose the age of the cat using the candles from your set. In other words, find the minimum number yy such that all numbers from 11 to y−1y−1 can be composed by digits from your set, but yy cannot be composed.

Input

The first line contains an integer tt (1≤t≤1041≤t≤104) — the number of test cases in the input.

The only line of each test case contains ten integer numbers c0,c1,…,c9c0,c1,…,c9 (0≤ci≤1050≤ci≤105) — the number of 00-candles, 11-candles, 22-candles and so on.

It is guaranteed that the sum of all cici in the input does not exceed 106106.

Output

For each test case, output one integer in single line — the minimum age which cannot be composed by candles from your set. Please note that the age can be quite large (it may exceed the standard 64-bit integer types in your programming language).

Example

input

Copy

4
1 1 1 1 1 1 1 1 1 1
0 0 1 1 2 2 3 3 4 4
1 2 1 2 1 3 1 0 0 0
0 1 2 1 4 3 1 1 2 1

output

Copy

11
1
7
10
#include<bits/stdc++.h>
using namespace std;
long long t,n,k;
long long a[11];
int main()
{
	cin>>t;
	while(t--)
	{
		int min1=1e5+10;
		k=-1;
		for(int i=0;i<=9;i++)
		{
			cin>>a[i];
		}
		a[10]=a[0];
		for(int i=1;i<=10;i++)
		{
			if(a[i]<min1)
			{
				min1=a[i];
				k=i;
			}
		}
		if(k!=10)
		{
			for(int i=1;i<=a[k]+1;i++)
			cout<<k;
		}
		else
		{
			cout<<1;
			for(int i=1;i<=a[k]+1;i++)
			cout<<0;
		}
		cout<<endl;
		
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值