CF479B.Towers
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a__i cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highest and the lowest of the towers. For example, if Petya built five cube towers with heights (8, 3, 2, 6, 3), the instability of this set is equal to 6 (the highest tower has height 8, the lowest one has height 2).
The boy wants the instability of his set of towers to be as low as possible. All he can do is to perform the following operation several times: take the top cube from some tower and put it on top of some other tower of his set. Please note that Petya would never put the cube on the same tower from which it was removed because he thinks it's a waste of time.
Before going to school, the boy will have time to perform no more than k such operations. Petya does not want to be late for class, so you have to help him accomplish this task.
众所周知,贝尔兰的所有孩子都喜欢玩积木。小彼佳有 n 座由相同大小的积木堆叠而成的塔。编号为 i 的塔由 ai 块积木垂直堆叠而成。彼佳将一组塔的不稳定性定义为其中最高塔与最低塔的高度之差。例如,若彼佳搭建了五座高度分别为 (8,3,2,6,3) 的积木塔,则该组塔的不稳定性为 6(最高塔高度为 8,最低塔高度为 2)。
男孩希望他这组塔的不稳定性尽可能小。他唯一能进行的操作是:多次执行以下操作——从某座塔的顶端取下一块积木,并将其放置到另一座塔的顶端。请注意,彼佳绝不会把积木放回它原本所在的那座塔上,因为他认为那样做是在浪费时间。
在上学之前,男孩最多只能执行 k 次这样的操作。彼佳不想上课迟到,因此你需要帮助他完成这项任务。
输入格式
The first line contains two space-separated positive integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000) — the number of towers in the given set and the maximum number of operations Petya can perform. The second line contains n space-separated positive integers a__i (1 ≤ a__i ≤ 104) — the towers' initial heights.
第一行包含两个用空格分隔的正整数 n 和 k(1 ≤ n ≤ 100,1 ≤ k ≤ 1000)—— 分别表示给定集合中塔的数量以及 Petya 最多可执行的操作次数。
第二行包含 n 个用空格分隔的正整数 ai(1 ≤ ai ≤ 104)—— 表示各塔的初始高度。
输出格式
In the first line print two space-separated non-negative integers s and m (m ≤ k). The first number is the value of the minimum possible instability that can be obtained after performing at most k operations, the second number is the number of operations needed for that.
In the next m lines print the description of each operation as two positive integers i and j, each of them lies within limits from 1 to n. They represent that Petya took the top cube from the i-th tower and put in on the j-th one (i ≠ j). Note that in the process of performing operations the heights of some towers can become equal to zero.
If there are multiple correct sequences at which the minimum possible instability is achieved, you are allowed to print any of them.
第一行输出两个用空格分隔的非负整数 s 和 m(其中 m≤k)。第一个数 s 是最多执行 k 次操作后所能达到的最小可能不稳定性值,第二个数 m 是达到该最小不稳定性所需的操作次数。
接下来 m 行,每行输出一次操作的描述,即两个正整数 i 和 j,均在 1 到 n 的范围内。它们表示 Petya 将第 i 座塔顶的方块取下,并将其放置到第 j 座塔上(其中 i=j)。注意:在执行操作的过程中,某些塔的高度可能变为零。
若存在多种能达到最小可能不稳定性值的正确操作序列,则任选其一输出即可。
输入输出样例
输入#1
3 2 5 8 5
输出#1
0 2 2 1 2 3
输入#2
3 4 2 2 4
输出#2
1 1 3 2
输入#3
5 3 8 3 2 6 3
输出#3
3 3 1 3 1 2 1 3
说明/提示
In the first sample you need to move the cubes two times, from the second tower to the third one and from the second one to the first one. Then the heights of the towers are all the same and equal to 6.
在第一个样例中,你需要移动方块两次:一次将方块从第二座塔移到第三座塔,另一次将方块从第二座塔移到第一座塔。此时,三座塔的高度均相同,均为 6。
输入解题思路,AI测评打分。不知道怎么写?