QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#18051. Interval Selection

统计

There is a sequence $a$ of length $n$.

Let $f(x) = 1$ if the value $x$ exists in the sequence $a$, and $f(x) = 0$ otherwise.

For each element in the sequence, you can either add $1$ to it or leave it unchanged. You need to perform operations on the sequence to maximize the length of an interval $[l, r]$ such that $\displaystyle\sum_{i=l}^{r} f(i) = r - l + 1$. Find this maximum length.

Input

The problem contains multiple test cases. The first line contains two positive integers $c$ and $t$, representing the Subtask ID and the number of test cases, respectively. Specifically, for the sample, $c = 0$.

For each test case:

  • The first line contains a positive integer $n$.
  • The second line contains $n$ positive integers representing the sequence $a$.

Output

For each test case:

  • Output a single positive integer representing your answer.

Examples

Input 1

0 3
9
1 1 3 4 6 6 6 8 10
6
1 2 3 4 5 6
5
10 10 10 10 10

Output 1

5
6
2

Note 1

For the first test case, change the sequence $a$ to $1, 2, 4, 5, 6, 6, 7, 8, 10$. The interval $[l, r]$ with the maximum $r - l + 1$ satisfying the condition is $[4, 8]$. It can be proven that this is the optimal strategy.

For the second test case, we can leave the sequence $a$ unchanged. The interval $[l, r]$ with the maximum $r - l + 1$ satisfying the condition is $[1, 6]$. It can be proven that this is the optimal strategy.

For the third test case, change the sequence $a$ to $10, 10, 10, 11, 11$. The interval $[l, r]$ with the maximum $r - l + 1$ satisfying the condition is $[10, 11]$. It can be proven that this is the optimal strategy.

Constraints

For all data, it is guaranteed that:

  • $1 \le t \le 10^5$;
  • $1 \le a_i, n \le 10^6$;
  • $\sum n \le 2 \times 10^6$.

This problem uses bundled testing. The special properties of each subtask are as follows:

Subtask $\sum n \le$ Special Properties Score
$1$ $10^4$ $n \le 10$ $10$
$2$ $10^4$ $n \le 100$ $15$
$3$ $10^4$ $n \le 500$ $15$
$4$ $10^4$ $n \le 1000$ $15$
$5$ $5 \times 10^5$ $a_i \le 100$ $15$
$6$ $5 \times 10^5$ None $15$
$7$ $2 \times 10^6$ None $15$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.