QOJ.ac

QOJ

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

#506. 礼物

统计

Alan 收到了 Bekzhan 送的一份不同寻常的生日礼物。这份礼物被一把数学锁锁住了。

这把锁包含 $N$ 个数字,位置编号从 $1$ 到 $N$。初始时,所有数字均为零。在一次操作中,Alan 可以选择一个整数 $X$ ($1 \le X$) 和锁上的 $K$ 个不同位置 $1 \le i_1, i_2, \dots, i_K \le N$,然后将 $X$ 加到位置 $i_1, i_2, \dots, i_K$ 上的所有值中。Bekzhan 还给出了打开这把锁的数字序列 $A_1, A_2, \dots, A_N$。数字的顺序很重要。

Alan 无法解决这个问题。请帮他解锁,或者确定解不存在。

注意,你不需要最小化操作次数。但 Alan 不希望总共选择超过 $3\,000\,000$ ($3 \cdot 10^6$) 个位置,即如果 $M$ 是解中的操作次数,且 $M \cdot K \le 3 \cdot 10^6$,则该解被认为是正确的,否则不正确。

输入格式

输入的第一行包含两个正整数 $N$ 和 $K$ ($2 \le K \le N \le 10^6$, $N \cdot K \le 2 \cdot 10^6$),分别表示锁中序列的长度和每次操作可以选择的位置数量。输入的第二行包含 $N$ 个正整数 $A_1, A_2, \dots, A_N$ ($1 \le A_i$,对于所有 $1 \le i \le N$,$\sum_{i=1}^N A_i \le 10^{18}$),由空格分隔,表示打开锁的数字序列。

输出格式

如果解不存在,输出 “-1”(不含引号)。否则,在第一行输出 $M$ —— 操作次数。在接下来的 $M$ 行中,第 $j$ 行输出 $X_j$,然后输出 $K$ 个不同的数字 $i_{j,1}, i_{j,2}, \dots, i_{j,K}$,分别表示第 $j$ 次操作增加的数值以及被增加数值的位置。

子任务

本题包含五个子任务,每个子任务中的测试数据满足以下约束:

  1. $\sum_{i=1}^N A_i \le 10, K = 2$。分值 7 分。
  2. $\sum_{i=1}^N A_i \le 10^5, K = 2$。分值 11 分。
  3. $\sum_{i=1}^N A_i \le 10^5$。分值 12 分。
  4. $A_1 = A_2 = \dots = A_N$。分值 19 分。
  5. 满足题目描述中的约束。分值 51 分。

样例

样例输入 1

4 2
2 3 3 2

样例输出 1

3
2 3 1
1 3 2
2 2 4

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.