Trees in a Row

CodeForces - 402B

The Queen of England has n trees growing in a row in her garden. At that, the i-th (1 ≤ i ≤ n) tree from the left has height ai meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all i (1 ≤ i < n), ai + 1 - ai = k, where k is the number the Queen chose.

Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes?

Input

The first line contains two space-separated integers: nk (1 ≤ n, k ≤ 1000). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the heights of the trees in the row.

Output

In the first line print a single integer p — the minimum number of minutes the gardener needs. In the next p lines print the description of his actions.

If the gardener needs to increase the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, print on the corresponding line "- j x".

If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them.

Examples

Input
4 1
1 2 1 5
Output
2
+ 3 2
- 4 1
Input
4 1
1 2 3 4
Output
0

sol:数据范围小的可怜,爆枚一个正确节点,n2模拟即可
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,a[N],b[N],Ans[N];
int main()
{
int i,j,Pos=-;
R(n); R(m);
for(i=;i<=n;i++) R(a[i]);
for(i=;i<=n;i++)
{
Ans[i]=;
b[i]=a[i];
for(j=i-;j>=;j--) b[j]=b[j+]-m;
for(j=i+;j<=n;j++) b[j]=b[j-]+m;
for(j=;j<=n;j++)
{
if(b[j]!=a[j]) Ans[i]++;
if(b[j]<=) {Ans[i]=0x3f3f3f3f; break;}
}
if((Pos==-)||(Ans[i]<Ans[Pos])) Pos=i;
}
Wl(Ans[Pos]);
b[Pos]=a[Pos];
for(i=Pos-;i>=;i--) b[i]=b[i+]-m;
for(i=Pos+;i<=n;i++) b[i]=b[i-]+m;
for(i=;i<=n;i++) if(a[i]!=b[i])
{
if(a[i]<b[i])
{
putchar('+'); putchar(' '); W(i); Wl(b[i]-a[i]);
}
else
{
putchar('-'); putchar(' '); W(i); Wl(a[i]-b[i]);
}
}
return ;
}
/*
Input
4 1
1 2 1 5
Output
2
+ 3 2
- 4 1 Input
4 1
1 2 3 4
Output
0
*/
 

codeforces402B的更多相关文章

随机推荐

  1. java8 List对象集合去重

    //测试数据 WaterMeter w0 = new WaterMeter(); WaterMeter w1 = new WaterMeter(); WaterMeter w2 = new Water ...

  2. 22-Perl Socket 编程

    1.Perl Socket 编程Socket又称"套接字",应用程序通常通过"套接字"向网络发出请求或者应答网络请求,使主机间或者一台计算机上的进程间可以通讯. ...

  3. Leaflet个人封装笔记

    <!DOCTYPE html> <html> <head> <link href="style/leaflet.css" type=&qu ...

  4. centos配置发送邮件

    邮件已经可以接收到了 CentOS下发送邮件有很多种方法,这里采用比较简单的mail客户端,配置第三方邮件服务商,例如:163.com 1.安装所用软件 yum install mailx sendm ...

  5. 公众平台第三方平台 .NET开发

    前言:本博客借鉴了很多三方内容整理的,参考博客:竹叶苿. 一.开发的目的(以下是引用官方的话) 公众平台第三方平台 是为了让公众号或小程序运营者,在面向垂直行业需求时,可以一键授权给第三方平台(并且可 ...

  6. webpack整合 vue-router 路由,模块嵌套,整合Mint UI,MUI

    webpack整合 vue-router 结构 各个文件内容,一共八个文件, 还有src components 目录 Login.vue <template> <div> &l ...

  7. Windows live Writer Tips

    http://lehsys.blogspot.com/2013/03/windows-live-writer-how-to-change.html http://www.carlosag.net/to ...

  8. 在 Sublime Text 3 中使用 SublimeClang 插件

    SublimeClang 是 Sublime Text 中唯一的 C/C++ 自动补全插件,功能强大,自带语法检查功能,可惜目前作者停止更新了,而且只支持 Sublime Text 2.今晚在 ST ...

  9. SQL语句复习【专题六】

    SQL语句复习[专题六] 用户 + 创建表  --创建一个新的用户,然后给新的用户创建一张表,然后给表中添加一些数据.查询表中的数据 --创建用户需要比较大的权限 DBA create user di ...

  10. Manticore search加一个中文分词

    Sphinx search 是一款非常棒的开源全文搜索引擎,它使用C++开发,索引和搜索的速度非常快,我使用sphinx的时间也有好多年了.最初使用的是coreseek,一个国人在sphinxsear ...