Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

include<bits/stdc++.

h>
#define inf 99999
using namespace std;
vector <int> a,x,p,kq;
int n, k, dmin= inf;
int main()
{
cin>>n>>k;
a.resize(n);
x.resize(n);
p.resize(n);
kq.resize(n);
for (int i=0; i<n; i++) cin>>a[i];
for (int j=0; j<1000; j++)
{
fill(x.begin(),x.end(),0);
fill(p.begin(), p.end(),0);
x[0]=k;
int d=0;
if (a[0]!=x[0]) d=1;
p[0]=x[0]-a[0];
for (int i=1; i<n; i++)
{
x[i]= x[i-1]+k;
if (x[i]!=a[i]) d++;
p[i]= x[i]- a[i];
}
if (dmin>d)
{
dmin=d;
kq=p;
}
}
cout<<dmin<<'\n';
for (int i=0; i<n; i++)
{
if (kq[i]<0) cout<<"-"<<i+1<<" "<<abs(kq[i])<<'\n';
if (kq[i]>0) cout<<"+"<<i+1<<" "<<abs(kq[i])<<'\n';
}
return 0;
}00000000

You might also like