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

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

d1000000

면접 대비

메모리 제한1024 MB

요약
여러 면체 주사위가 주어질 때, 각 주사위에서 하나씩 골라 만들 수 있는 가장 긴 연속된 수의 직선을 구한다.
난이도

보통10점 중 4점

유형
그리디, 정렬
정답자
아직 제출이 없습니다

문제

While the most typical type of dice have 66 sides, each of which shows a different integer 11 through 66, there are many games that use other types. In particular, a dkdk is a die with kk sides, each of which shows a different integer 11 through kk. A d6d6 is a typical die, a d4d4 has four sides, and a d1000000d1000000 has one million sides.

In this problem, we start with a collection of NN dice. The ii-th die is a dS_idS\_i, that is, it has S_iS\_i sides showing integers 11 through S_iS\_i. A straight of length ℓℓ starting at xx is the list of integers x,x+1,…,x+(ℓ−1)x,x+1,\dots ,x+(ℓ-1). We want to choose some of the dice (possibly all) and pick one number from each to form a straight. What is the longest straight we can form in this way?

입력

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case is described in two lines. The first line of a test case contains a single integer NN, the number of dice in the game. The second line contains NN integers S_1,S_2,…,S_NS\_1,S\_2, \dots ,S\_N, each representing the number of sides of a different die.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the maximum number of input dice that can be put in a straight.

제한

  • 1≤T≤1001≤T≤100.

힌트

In Sample Case #1, there are multiple ways to form a straight using all 44 dice. One possible way is shown in the image above.

In Sample Case #2, since none of the dice can show an integer greater than 55, there is no way to have a straight with more than 55 dice. There are multiple ways to form a straight with exactly 55 dice. For example, pick the integers 44 and 55 for both d5d5⁠'s and then integers 11, 22, and 33 for three of the d4d4⁠'s to form 11, 22, 33, 44, 55.

In Sample Case #3, it is possible to form the straight 11, 22, 33, 44, 55, 66, 77, 88, 99 by discarding one d4d4 and using the d4d4⁠'s, d5d5, and d6d6 to get 11 through 44; the d7d7⁠'s to get 55 through 77; and the d10d10⁠'s to get 88 and 99. There is no way to form a straight of length 1010, so this is the best that can be done.

In Sample Case #4, we can only form a straight of length 11, but we can do so by picking any integer for the d10d10 we are given.

예제1

  1. 예제 1

    입력
    4
    4
    6 10 12 8
    6
    5 4 5 4 4 4
    10
    10 10 7 6 7 4 4 5 7 4
    1
    10
    
    예상 출력
    Case #1: 4
    Case #2: 5
    Case #3: 9
    Case #4: 1