QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓

#11766. K-正则数组

Statistiques

如果一个长度为 $n$ 的数组 $a$ 的每一个长度为 $k$ 的子数组都包含 $1$ 到 $k$ 的所有整数,则称该数组为 $k$-正则数组。

例如,$a = [2, 1, 3, 2]$ 是 $3$-正则的,因为它的两个长度为 $3$ 的子数组分别是 $[2, 1, 3]$ 和 $[1, 3, 2]$,每个子数组都包含了 $1$ 到 $3$ 的所有整数。另一方面,$a = [1, 2, 3, 4]$ 不是 $3$-正则的,因为长度为 $k = 3$ 的子数组 $[2, 3, 4]$ 不包含 $1$。

你的任务是找到一个长度为 $n$ 的 $k$-正则数组 $a$,使得其元素之和最大。

输入格式

输入的第一行包含一个整数 $t$ ($1 \le t \le 10^4$),表示测试用例的数量。接下来是各测试用例的描述。

每个测试用例由一行组成,包含两个整数 $n$ 和 $k$ ($1 \le k \le n \le 2 \cdot 10^5$),分别表示数组 $a$ 的目标长度和上述参数 $k$。

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

输出格式

对于每个测试用例,输出一行,包含 $n$ 个整数 $a_1, a_2, \dots, a_n$,表示一个元素之和最大的长度为 $n$ 的 $k$-正则数组 $a$。

如果存在多个解,输出任意一个即可。

样例

输入 1

4
4 3
5 1
3 2
1 1

输出 1

3 1 2 3
1 1 1 1 1
2 1 2
1

说明

在第一个样例中,数组 $a = [3, 1, 2, 3]$ 是 $3$-正则的,因为它的两个长度为 $3$ 的子数组分别是 $[3, 1, 2]$ 和 $[1, 2, 3]$,每个子数组都包含了 $1$ 到 $3$ 的所有整数。该数组的和为 $3 + 1 + 2 + 3 = 9$,可以证明这是对于给定 $n$ 和 $k$ 的最大和。

在第二个样例中,每个长度为 $1$ 的子数组必须包含 $1$,因此该数组必须全部由 $1$ 组成。

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.