Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

Prof.Hui 是 Pigeland 大学程序设计队的教练。他的队里有 $n$ 名学生。Prof.Hui 将所有算法按难度升序编号,从 $1$ 到 $m$。这意味着算法 $1$ 是最简单的算法,而算法 $m$ 是最难的。第 $i$ 名学生掌握的是第 $a_i$ 个最简单的算法。

现在 Prof.Hui 想要挑选一个满足以下条件的队伍:

  • 队伍中学生的编号构成一个区间。这意味着存在两个整数 $l, r$,满足 $1 \le l \le r \le n$,且学生 $x$ 在队伍中当且仅当 $l \le x \le r$。
  • 队伍的评分最大化。队伍掌握的算法越多,他们就越强,但如果他们在比赛中无法解决一道难题,他们会感到更加失望。因此,队伍的评分定义为:队伍中学生掌握的不同算法的数量,减去队伍中无人掌握的最简单算法的编号。如果队伍掌握了所有算法,则认为队伍中无人掌握的最简单算法的编号为 $m + 1$。例如,如果 $m = 5$,队伍中有 $6$ 名学生,分别掌握算法 $2, 5, 4, 4, 1, 1$,则该队伍的评分为 $4 - 3 = 1$。

请帮助 Prof.Hui 找到队伍的最大评分。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 5 \cdot 10^5$),表示测试用例的数量。

对于每个测试用例,第一行包含两个整数 $n, m$ ($1 \le n, m \le 5 \cdot 10^5$),分别表示学生人数和算法数量。

第二行包含 $n$ 个整数,第 $i$ 个整数 $a_i$ ($1 \le a_i \le m$) 表示第 $i$ 名学生掌握的算法编号。

保证所有测试用例中 $n$ 的总和不超过 $5 \cdot 10^5$。请注意,对 $m$ 的总和没有限制。

输出格式

对于每个测试用例,输出一行一个整数,表示答案。

样例

输入 1

2
5 4
1 2 2 3 4
5 10000
5 2 3 4 1

输出 1

2
3

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.