QOJ.ac

QOJ

Time Limit: 4 s - 8 s Memory Limit: 1024 MB Total points: 16

#5872. Dire Straights

الإحصائيات

Problem

You are playing a card game, where each card has an integer number written on it.

To play the game, you are given some cards — your hand. Then you arrange the cards in your hand into straights. A straight is a set of cards with consecutive values; e.g. the three cards {3, 4, 5}, or the single card {7}. You then receive a number of dollars equal to the length of the shortest straight. If you have no cards, you can form no straights, so you get zero dollars.

You will be given a series of test cases, each of which describes the cards you will have in your hand. Find the maximum number of dollars you can receive for each test case.

Input

The first line of the input contains the number of test cases, T.

Each test case consists of one line. Each line contains N, the number of cards in your hand, followed by N integers giving the numbers on those cards. These numbers are all space-separated.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the maximum number of dollars you can receive.

Limits

1 ≤ T ≤ 100

The numbers on the cards are between 1 and 10000.

Memory limit: 1GB.

Small dataset (Test set 1 - Visible; 4 Points)

0 ≤ N ≤ 10

Time limit: 30 4 seconds.

Large dataset (Test set 2 - Hidden; 12 Points)

0 ≤ N ≤ 1000

Time limit: 60 8 seconds.

Sample

4
10 1 2 3 4 5 10 9 8 7 6
8 101 102 103 104 105 106 103 104
0
5 1 2 3 4 9
Case #1: 10
Case #2: 4
Case #3: 0
Case #4: 1

In case 1, you have ten cards numbered 1 to 10, so you make one straight of length 10, and get 10 dollars.

In case 2, you could make two straights {101,102,103,104,105,106} and {103,104} and get 2 dollars. But it would be better to make {101,102,103,104} and {103,104,105,106} and get 4 dollars.

In case 4, the card with the number 9 must be in a straight containing only that card. So you get 1 dollar.

In case 3, you have zero cards, so you get zero dollars. You don't get money for nothing.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.