302486: CF479B. Towers

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Towers

题意翻译

如你所知,柏林所有的孩子都喜欢玩方块。小佩提亚有n座塔,由大小相同的立方体组成。一个塔由一个叠在另一个上面的立方体组成。佩蒂亚将一组塔的不稳定性定义为等于塔的最高和最低高度之间的差的值。例如,如果佩蒂亚建造了五个高度为(8、3、2、6、3)的立方体塔,那么这组塔的不稳定性等于6(最高的塔有8个高度,最低的塔有2个高度)。 这个男孩希望他的塔群的不稳定性尽可能低。他所能做的就是多次执行以下操作:从某个塔架上取下顶部立方体,并将其放在另一个塔架上。请注意,佩蒂亚不会把立方体放在同一个塔上,因为他认为这是浪费时间。 在上学之前,这个男孩将有时间进行不超过k次这样的操作。佩蒂亚不想上课迟到,所以你必须帮助他完成这项任务。

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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.

输入输出样例

输入样例 #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.

Input

题意翻译

如你所知,柏林所有的孩子都喜欢玩方块。小佩提亚有n座塔,由大小相同的立方体组成。一个塔由一个叠在另一个上面的立方体组成。佩蒂亚将一组塔的不稳定性定义为等于塔的最高和最低高度之间的差的值。例如,如果佩蒂亚建造了五个高度为(8、3、2、6、3)的立方体塔,那么这组塔的不稳定性等于6(最高的塔有8个高度,最低的塔有2个高度)。 这个男孩希望他的塔群的不稳定性尽可能低。他所能做的就是多次执行以下操作:从某个塔架上取下顶部立方体,并将其放在另一个塔架上。请注意,佩蒂亚不会把立方体放在同一个塔上,因为他认为这是浪费时间。 在上学之前,这个男孩将有时间进行不超过k次这样的操作。佩蒂亚不想上课迟到,所以你必须帮助他完成这项任务。

加入题单

算法标签: