QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓
統計

Panda 在一维数轴的非负半轴上有 $n$ 个线段。第 $i$ 个线段的左端点是 $l_i$。每个线段的长度都相同,均为 $L$。这意味着第 $i$ 个线段覆盖了闭区间 $[l_i, l_i + L - 1]$。

现在,Panda 希望你求出,在至多移动一个线段后,数轴非负半轴上被恰好覆盖 $k$ 次的整点数量的最大值。具体来说,你被允许选择至多一个线段,并将其左端点修改为任意非负整数(没有上限)。线段的长度 $L$ 保持不变。

输入格式

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

对于每个测试用例,第一行包含三个正整数 $n, L, k$ ($1 \le n \le 2 \times 10^5$, $1 \le L \le n$, $1 \le k \le n$)。其中 $n$ 是线段的总数,$L$ 是每个线段的固定长度,$k$ 是要求的覆盖次数。

第二行包含 $n$ 个非负整数。第 $i$ 个整数为 $l_i$ ($0 \le l_i \le 2 \times n$),表示第 $i$ 个线段的左端点。

保证所有测试用例中 $n$ 的总和不超过 $2 \times 10^5$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示在至多移动一个线段后,能够被恰好覆盖 $k$ 次的整点数量的最大值。

样例

输入样例 1

3
3 2 1
2 6 2
3 3 2
6 2 0
5 1 3
5 6 7 8 9

输出样例 1

6
3
0

说明

对于样例中的第一个测试用例,最初三个线段分别为 $[2, 3]$、$[6, 7]$ 和 $[2, 3]$。你可以将第三个线段的左端点修改为 $114514$。移动后,线段变为 $[2, 3]$、$[6, 7]$ 和 $[114514, 114515]$。这使得恰好被覆盖一次的整点数量为 6,这是可以达到的最大值。

对于第二个测试用例,你可以将第一个线段的左端点移动到 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.