纯暴力.....

B. Towers
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ai 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.

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 2
5 8 5
output
0 2
2 1
2 3
input
3 4
2 2 4
output
1 1
3 2
input
5 3
8 3 2 6 3
output
3 3
1 3
1 2
1 3
Note

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.


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; int n,k; struct TA
{
int x,id;
}ta[200]; bool cmp(TA a,TA b)
{
return a.x<b.x;
} vector<int> ans; int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
ta[i].x=x; ta[i].id=i;
}
while(k--)
{
sort(ta+1,ta+1+n,cmp);
int diff=ta[n].x-ta[1].x;
if(diff==0) break;
else
{
ta[n].x--; ta[1].x++;
ans.push_back(ta[n].id);
ans.push_back(ta[1].id);
}
}
sort(ta+1,ta+1+n,cmp);
int diff=ta[n].x-ta[1].x;
int sz=ans.size();
printf("%d %d\n",diff,sz/2);
for(int i=0;i<sz;i+=2)
{
printf("%d %d\n",ans[i],ans[i+1]);
}
return 0;
}

Codeforces 479B. Towers 暴力的更多相关文章

  1. codeforces 479B Towers 解题报告

    题目链接:http://codeforces.com/problemset/problem/479/B 题目意思:有 n 座塔,第 i 座塔有 ai 个cubes在上面.规定每一次操作是从最多 cub ...

  2. Karen and Game CodeForces - 816C (暴力+构造)

    On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as fo ...

  3. Chladni Figure CodeForces - 1162D (暴力,真香啊~)

    Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circ ...

  4. Codeforces 229D Towers

    http://codeforces.com/problemset/problem/229/D 题意:有n(1<=n<=5,000)座塔排在一条直线上,从左到右每个塔的高度分别为hi(1&l ...

  5. Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)

    The only difference between easy and hard versions is a number of elements in the array. You are giv ...

  6. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  7. CodeForces - 589B(暴力)

    题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...

  8. CodeForces - 589B(暴力+排序)

    Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...

  9. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

    题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...

随机推荐

  1. 【C++】异常简述(二):C++的异常处理机制

    上文简述了在C语言中异常的处理机制,本文主要讲解C++中的异常处理. 一.异常的语法格式 在C++中,异常的抛出和处理主要使用了以下三个关键字:try. throw . catch.其格式如下: 当我 ...

  2. Node.js——require加载规则

    判断require中的标识参数: 非路径的标识参数:也被称为是核心模块,已经被编译到二进制文件中 带有路径标识参数:自定义模块,一般都是相对定位 第三方模块:表现形式与核心模块一样,但是实际不一样,它 ...

  3. vim 将文件所有行合并到一行

      vim 将文件所有行合并到一行   在 Normal Mode下执行: ggvGJ gg 用于跳到行首 v 转换成 visual 模式 G 跳到最后一行 J 合并行

  4. vue工程化引入组件模板

    vue脚手架搭建好项目后,组件间的引用通过components import bannerComponent from './banner' export default { data(){ retu ...

  5. 检查sql对象是否存在

    SQL Server判断对象是否存在   1 判断数据库是否存在 Sql代码  if exists (select * from sys.databases where name = '数据库名')  ...

  6. python beautifulsoup获取特定html源码

    beautifulsoup 获取特定html源码(无需登录页面) import refrom bs4 import BeautifulSoupimport urllib2 url = 'http:// ...

  7. ios中摄像头/相册获取图片压缩图片上传服务器方法总结

    本文章介绍了关于ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结,有需要了解的同学可以参考一下下.     这几天在搞iphone上面一个应用的开发,里面有需要摄像头/相册编程和图片上传的问 ...

  8. [Luogu] P4838 P哥破解密码

    题目背景 P哥是一个经常丢密码条的男孩子. 在ION 8102赛场上,P哥又弄丢了密码条,笔试满分的他当然知道这可是要扣5分作为惩罚的,于是他开始破解ION Xunil系统的密码. 题目描述 定义一个 ...

  9. [Python3网络爬虫开发实战] 1.9.3-Scrapyd-Client的安装

    在将Scrapy代码部署到远程Scrapyd的时候,第一步就是要将代码打包为EGG文件,其次需要将EGG文件上传到远程主机.这个过程如果用程序来实现,也是完全可以的,但是我们并不需要做这些工作,因为S ...

  10. [Python3网络爬虫开发实战] 1.9.2-Scrapyd的安装

    Scrapyd是一个用于部署和运行Scrapy项目的工具,有了它,你可以将写好的Scrapy项目上传到云主机并通过API来控制它的运行. 既然是Scrapy项目部署,基本上都使用Linux主机,所以本 ...