QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#14716. K-被覆

Estadísticas

Panda は 1 次元の数直線を持っており、その非負の部分に $n$ 個の線分が置かれています。$i$ 番目の線分の左端点は $l_i$ です。すべての線分の長さは等しく $L$ です。つまり、$i$ 番目の線分は閉区間 $[l_i, l_i + L - 1]$ を覆っています。

いま Panda は、高々 1 個の線分を移動させた後に、数直線の非負の部分においてちょうど $k$ 回覆われる整数点の個数の最大値を求めてほしいと考えています。具体的には、高々 1 個の線分を選び、その左端点を(上限のない)任意の非負整数に変更することができます。線分の長さ $L$ は変わりません。

入力

1 行目にはテストケースの個数を表す整数 $T$($1 \le T \le 2 \times 10^5$)が与えられます。

各テストケースについて、1 行目には 3 つの正の整数 $n, L, k$($1 \le n \le 2 \times 10^5$、$1 \le L \le n$、$1 \le k \le n$)が与えられます。$n$ は線分の総数、$L$ は各線分の固定された長さ、$k$ は求められる被覆回数です。

2 行目には $n$ 個の非負整数が与えられます。$i$ 番目の整数は $l_i$($0 \le l_i \le 2 \times n$)であり、$i$ 番目の線分の左端点を表します。

すべてのテストケースにおける $n$ の総和は $2 \times 10^5$ を超えないことが保証されます。

出力

各テストケースについて、高々 1 個の線分を移動させた後にちょうど $k$ 回覆われる整数点の個数の最大値を表す整数を 1 行に出力してください。

入出力例

入力 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

注記

サンプルの 1 つ目のテストケースでは、最初は 3 つの線分が $[2, 3]$、$[6, 7]$、$[2, 3]$ です。3 番目の線分の左端点を $114514$ に変更すると、移動後の線分は $[2, 3]$、$[6, 7]$、$[114514, 114515]$ となります。これにより、ちょうど 1 回覆われる整数点は $6$ 個となり、これが達成可能な最大値です。

2 つ目のテストケースでは、1 番目の線分の左端点を $3$ に移動させることで、ちょうど 2 回覆われる整数点の個数を最大化できます。

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.