아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Town

시간 제한1초메모리 제한1024 MB

요약
0부터 9까지 각 숫자 플라스틱 조각의 개수가 주어질 때, 1부터 x까지의 번호를 모두 붙일 수 있는 가장 큰 x를 구한다.
난이도

보통10점 중 6점

유형
수학, 그리디, 이분 탐색
정답자
아직 제출이 없습니다

문제

You are standing in a town with infinitely many houses. Currently, the houses do not have any house numbers. You were given the task to fix this.

You have a box with plastic digits. For each i between 0 and 9, inclusive, there are d**i copies of the digit i in your box. You can number a house by sticking the appropriate digits to its wall. For example, on the house number 474 you will use two digits 4 and one digit 7.

You have decided that you will number the houses sequentially, starting from 1. How many houses can you number before you run out of digits?

You are given the counts d0, …, d9 of the digits in your box. Find the largest x such that you are able to write the numbers 1 through x using your set of digits.

입력

The first line of the input file contains an integer t specifying the number of test cases. Each test case is preceded by a blank line. Each test case consists of a single line containing 10 nonnegative integers – the counts of digits 0 through 9.

출력

For each test case, output a single line with the answer to the test case.

힌트

With the digits you have, you are able to build the numbers 1 through 10. Once you do so, you will be left with three digits: one 1, one 4, and one 7. This is not enough to construct the number 11.

예제1

  1. 예제 1

    입력
    1
    
    1 3 1 1 2 1 1 2 1 1
    
    예상 출력
    10