A9569 | Towers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted