#P12981. [GCJ 2022 Qualification] d1000000

    ID: 12776 Type: RemoteJudge 5000~15000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 2 Uploaded By: Tags>2022排序Google Code Jam

[GCJ 2022 Qualification] d1000000

题目描述

While the most typical type of dice have 6 sides, each of which shows a different integer 1 through 6, there are many games that use other types. In particular, a dkd_k is a die with kk sides, each of which shows a different integer 1 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 N\mathbf{N} dice. The ii-th die is a dSid\mathbf{S}_i, that is, it has Si\mathbf{S}_i sides showing integers 1 through Si\mathbf{S}_i. A straight of length \ell starting at xx is the list of integers xx, x+1x + 1, \cdots, x+(1)x + (\ell - 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, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case is described in two lines. The firstline of a test case contains a single integer N\mathbf{N}, the number of dice in the game. The second line contains N\mathbf{N} integers S1\mathbf{S}_1, S2\mathbf{S}_2, \cdots, SN\mathbf{S}_\mathbf{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.

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

提示

Sample Explanation

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 1,21, 2, and 33 for three of the d4d4's to form 1,2,3,4,51, 2, 3, 4, 5.

In Sample Case #3, it is possible to form the straight 1,2,3,4,5,6,7,8,91, 2, 3, 4, 5, 6, 7, 8, 9 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.

Limits

  • 1T1001 \leq \mathbf{T} \leq 100.

Test Set 1 (9 Pts, Visible Verdict)

  • 1N101 \leq \mathbf{N} \leq 10.
  • 4Si204 \leq \mathbf{S}_i \leq 20, for all ii.

Test Set 2 (11 Pts, Visible Verdict)

  • 1N1051 \leq \mathbf{N} \leq 10^5.
  • 4Si1064 \leq \mathbf{S}_i \leq 10^6, for all ii.