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
*/
 

最新文章

  1. iOS事件传递-&gt;处理-&gt;响应
  2. 团队项目——站立会议 DAY11
  3. Web前端优化最佳实践及工具集锦
  4. MongoDB的安全(五)
  5. Lua.LearningLua.7-userdata
  6. Spring强制使用CGLIB代理事务
  7. poj 1611 The Suspects(简单并查集)
  8. 24种设计模式--迭代模式【Iterator Pattern】
  9. UVA 11212 Editing a Book
  10. iOS多线程的基本使用
  11. Spring总结_02_Spring概述
  12. servlet上传文件报错(二)
  13. mysql order by 排序的问题
  14. 避免写慢SQL
  15. 斯巴达克斯诅咒者之战第三季/全集Spartacus迅雷下载
  16. git-采集编码搜索
  17. Oracle EBS AR 收款API收款方法标识无效
  18. SqlHelper类的编写
  19. 在返回值拒绝——reference
  20. CodeForces - 996B

热门文章

  1. Java 线程控制
  2. MySQL中的DML、DQL和子查询
  3. 5.Shell变量
  4. vue项目性能优化总结
  5. 1 C# 将对象序列化
  6. EBS常用表_Dictionary
  7. bizcharts在火狐上的Invalid date报错
  8. fastadmin中关联表时A为主表,想让B表和C表关联时怎么办?
  9. 【转】container_of宏 分析
  10. linux使用nginx配置web服务器