FZU2216 :The Longest Straight

时间限制:1000MS    内存限制:32768KByte   64位IO格式:%I64d & %I64u
描述

ZB is playing a card game where the goal is to make straights. Each card in the deck has a number between 1 and M(including 1 and M). A straight is a sequence of cards with consecutive values. Values do not wrap around, so 1 does not come after M. In addition to regular cards, the deck also contains jokers. Each joker can be used as any valid number (between 1 and M, including 1 and M).

You will be given N integers card[1] .. card[n] referring to the cards in your hand. Jokers are represented by zeros, and other cards are represented by their values. ZB wants to know the number of cards in the longest straight that can be formed using one or more cards from his hand.

输入

The first line contains an integer T, meaning the number of the cases.

For each test case:

The first line there are two integers N and M in the first line (1 <= N, M <= 100000), and the second line contains N integers card[i] (0 <= card[i] <= M).

输出

For each test case, output a single integer in a line -- the longest straight ZB can get.

样例输入
2
7 11
0 6 5 3 0 10 11
8 1000
100 100 100 101 100 99 97 103
样例输出
5
3
题目来源
第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学)
[提交] [状态]

|返回 |   | 转到页头|
Copyright @ 2008-2025 (浙ICP备2022001332号), TZOJ. All Rights Reserved.
2017-2025 台州市非普软件技术有限公司,浙江省台州市君悦大厦B幢1603室