CF1119G.Get Ready for the Battle

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Recently Evlampy installed one interesting computer game, one of aspects of which is to split army into several groups and then fight with enemy's groups. Let us consider a simplified version of the battle.

In the nearest battle Evlampy should fight an enemy army that consists of mm groups, the ii-th of which has hpihp_i health points.

Evlampy's army consists of nn equal soldiers. Before each battle he should split his army in exactly mm groups (possibly, empty) so that the total size of the groups is nn. The battle is played step-by-step. On each step each of Evlampy's groups attacks exactly one enemy group. Thus, each step is described with an array of mm integers a1,a2,…,ama_1, a_2, \ldots, a_m, meaning that the ii-th Evlampy's group attacks the aia_i-th enemy group. Different groups can attack same group, on each step the array aa is chosen independently.

After each step the health points of each enemy group decreases by the total number of soldiers in Evlampy's groups that attacked this enemy group at this step. Enemy group is destroyed once its health points are zero or negative. Evlampy's soldiers do not lose health.

An example of a step. The numbers in green circles represent the number of soldiers in Evlampy's groups, the arrows represent attacks, the numbers in red circles represent health points of enemy groups, the blue numbers represent how much the health points will decrease after the step.

Evlampy understands that the upcoming battle will take the whole night. He became sad because this way he won't have enough time to finish his homework. Now Evlampy wants you to write a program that will help him win in the smallest possible number of steps. Can you help him?

In other words, find the smallest number of steps needed to destroy all enemy groups and show a possible way of doing this. Find the requires splitting of the army into mm groups and the arrays aa for each step.

最近,Evlampy 安装了一款有趣的电脑游戏,其中一种玩法是将己方军队划分为若干组,然后与敌方各组进行战斗。我们来考虑该战斗的一个简化版本。

在即将到来的战斗中,Evlampy 需要迎战一支由 mm 个小组组成的敌军,其中第 ii 个小组具有 hpihp_i 点生命值。

Evlampy 的军队由 nn 名完全相同的士兵组成。在每次战斗开始前,他必须将这支军队恰好划分为 mm 组(允许某些组为空),使得所有组的士兵总数为 nn。战斗以“步”为单位逐步进行。在每一步中,Evlampy 的每一组士兵恰好攻击敌方的一个小组。因此,每一步可用一个长度为 mm 的整数数组 a1,a2,…,ama_1, a_2, \ldots, a_m 来描述:表示 Evlampy 的第 ii 组攻击敌方的第 aia_i 组。不同小组可以攻击同一敌方小组;且每一步所选的数组 aa 相互独立。

每一步结束后,每个敌方小组的生命值会减少——其减少量等于本步中攻击该敌方小组的所有 Evlampy 小组的士兵总数。一旦某敌方小组的生命值降至零或更低,即视为被摧毁。Evlampy 的士兵不会损失生命值。

一步战斗的示例图。绿色圆圈中的数字表示 Evlampy 各小组的士兵数量,箭头表示攻击关系,红色圆圈中的数字表示敌方各小组当前生命值,蓝色数字表示本步后各敌方小组生命值的减少量。

Evlampy 意识到这场战斗将持续整整一晚,因此感到沮丧——这样一来他就没有足够时间完成作业了。现在,Evlampy 希望你能编写一个程序,帮助他在最少的步数内获胜。你能帮他吗?

换言之,请找出摧毁全部敌方小组所需的最小步数,并给出一种可行方案:包括初始时将 nn 名士兵划分为 mm 组的具体方式,以及每一步所对应的攻击数组 aa。

输入格式

The first line contains two integers nn and mm (1≤m≤n≤1061 \leq m \leq n \leq 10^{6}) — the number of soldiers in Evlampy's army and the number of groups in enemy army. mm is also equal to the maximum possible number of groups Evlampy can split the army to.

The second line contains mm integers hp1,hp2,…,hpmhp_1, hp_2, \ldots, hp_m (1≤hpi≤1061 \leq hp_i \leq 10^{6}) — the health points of each of the enemy groups.

It is guaranteed that the sum of hpihp_i does not exceed 10610^{6}.

第一行包含两个整数 nn 和 mm(1≤m≤n≤1061 \leq m \leq n \leq 10^{6})—— 分别表示埃夫拉姆皮军队中的士兵总数以及敌军的组数。mm 同时也等于埃夫拉姆皮可将己方军队划分出的最大组数。

第二行包含 mm 个整数 hp1,hp2,…,hpmhp_1, hp_2, \ldots, hp_m(1≤hpi≤1061 \leq hp_i \leq 10^{6})—— 表示敌军每组的血量。

保证所有 hpihp_i 的总和不超过 10610^{6}。

输出格式

Print a single integer tt — the minimum possible number of steps needed to win the battle.

After that print mm integers s1,s2,…,sms_1, s_2, \ldots, s_m (si≥0s_i \ge 0, s1+s2+…+sm=ns_1 + s_2 + \ldots + s_m = n), meaning that the ii-th group of Evlampy's army should contain sis_i soldiers.

In each of the next tt lines print mm integers a1,a2,…,ama_1, a_2, \ldots, a_m (1≤ai≤m1 \le a_i \le m) — the description of one step. The integers mean that on the corresponding step the ii-th Evlampy's group should attack the aia_i-th enemy group. It is allowed to attack an already destroyed group.

输出一个整数 tt —— 获胜所需的最少步数。

随后输出 mm 个整数 s1,s2,…,sms_1, s_2, \ldots, s_m(满足 si≥0s_i \ge 0 且 s1+s2+…+sm=ns_1 + s_2 + \ldots + s_m = n),表示伊夫拉姆皮军队的第 ii 组应包含 sis_i 名士兵。

接下来的 tt 行中,每行输出 mm 个整数 a1,a2,…,ama_1, a_2, \ldots, a_m(满足 1≤ai≤m1 \le a_i \le m),描述一步操作。这些整数表示:在该步中,伊夫拉姆皮的第 ii 组应攻击敌方的第 aia_i 组。允许攻击已被摧毁的敌方小组。

输入输出样例

  • 输入#1

    13 7
    6 4 3 7 2 1 5

    输出#1

    3
    0 1 2 3 1 2 4
    2 6 2 4 4 2 4
    3 1 7 1 7 7 1
    3 1 5 3 7 5 1
  • 输入#2

    6 5
    3 3 3 3 3

    输出#2

    3
    3 3 0 0 0
    1 2 3 4 5
    3 4 5 5 5
    5 5 5 5 5
  • 输入#3

    7 4
    1 5 9 2

    输出#3

    3
    1 2 4 0
    1 4 2 3
    2 3 3 3
    3 3 3 3

说明/提示

The first example is shown below.

第一个示例如下所示。

输入解题思路,AI测评打分。不知道怎么写?

首页