Codeforces Round #274 (Div. 2) B. Towers_html/css_WEB-ITnose
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.
Input
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 ai (1?≤?ai?≤?104) ? the towers' initial heights.
Output
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.
Sample test(s)
input
3 25 8 5
output
0 22 12 3
input
3 42 2 4
output
1 13 2
input
5 38 3 2 6 3
output
3 31 31 21 3题意: 给出n个塔,由a[i]个砖块堆起来,整个体系的稳定系数为:最高的高度减去最矮的高度。 可以移动k次,求移动k次中,可以得到的最低的稳定系数,以及如何移动,每次只能移动1个方块。
思路:模拟
#include#include #include #include using namespace std;const int maxn = 1005;struct Node { int x, id;} node[maxn];struct Op { int x, y;} q[maxn];int ans[maxn];bool cmp(Node a, Node b) { return a.x
上一篇: 平衡二叉树操作
下一篇: 这个正则啥意思?该如何解决
推荐阅读
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #461 (Div. 2) B. Magic Forest(异或的性质)
-
Codeforces Round #663 (Div. 2) B. Fix You
-
Codeforces Round #658 (Div. 2) B. Sequential Nim
-
B. Power Sequence(数学+枚举)Codeforces Round #666 (Div. 2)
-
Codeforces Round #666 (Div. 2)B. Power Sequence(等比数列)
-
Codeforces Round #664 (Div. 2) B. Boboniu Plays Chess
-
Codeforces Round #156 (Div. 2)-A. Greg's Workout_html/css_WEB-ITnose
-
Codeforces Round #107 (Div. 2)-A. Soft Drinking_html/css_WEB-ITnose
-
Codeforces Round #191 (Div. 2)-A. Flipping Game_html/css_WEB-ITnose