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. 25-Perl CGI编程

    1.Perl CGI编程什么是CGICGI 目前由NCSA维护,NCSA定义CGI如下:CGI(Common Gateway Interface),通用网关接口,它是一段程序,运行在服务器上如:HTT ...

  2. 作业2:java内存模型图示

    参考:http://www.infoq.com/cn/minibooks/java_memory_model?utm_source=infoq&utm_campaign=user_page&a ...

  3. 三、maven学习-高级

    maven父子工程

  4. python 的面试题总汇

    函数作用域; LEGB : L>E>G>B L : local函数内部作用域 E : enclosing函数内部与内嵌函数之间 G : global全局作用域 B : build-i ...

  5. 深入理解hadoop之排序

    MapReduce的排序是默认按照Key排序的,也就是说输出的时候,key会按照大小或字典顺序来输出,比如一个简单的wordcount,出现的结果也会是左侧的字母按照字典顺序排列.下面我们主要聊聊面试 ...

  6. 转:GitHub团队项目合作流程

    转自:https://www.cnblogs.com/schaepher/p/4933873.html GitHub团队项目合作流程   已在另一篇博客中写出关于以下问题的解决,点此进入: 同步团队项 ...

  7. 创建json对象

    jQuery创建json对象 方法二: <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...

  8. 阿里云 elasticsearch 增删改查

    kibana 控制台 # 查询所有数据 GET /yixiurds_dev/_search { "query": { "match_all": { } } } ...

  9. ubuntu - 14.04,安装Git(源代码管理工具)

    在shell中执行:sudo apt-get install git-core

  10. current status of the installation and the internationalization of Samba 3.0

    Only about 8 months from release of Samba 3.0.0, there is beginning to be the transition from 2.2.x. ...