E. Arthur and Questions



time limit per test



memory limit per test



input



output



n (a1, a2, ..., an), consisting of integers and integer k, not exceeding n.

k consecutive elements (a1  +  a2 ...  +  ak,  a2  +  a3  +  ...  +  ak + 1,  ...,  an - k + 1  +  an - k + 2  +  ...  +  an), then those numbers will form strictly increasing sequence.

n = 5,  k = 3,  a = (1,  2,  4,  5,  6) the sequence of numbers will look as follows: (1  +  2  +  4,  2  +  4  +  5,  4  +  5  +  6) = (7,  11,  15), that means that sequence a

n - k + 1

|ai|, where |ai| is the absolute value of ai.



Input



n and k (1 ≤ k ≤ n ≤ 105), showing how many numbers are in Arthur's sequence and the lengths of segments respectively.

n space-separated elements ai (1 ≤ i ≤ n).

ai, then the i-th element of Arthur's sequence was replaced by a question mark.

ai (9 ≤ ai ≤ 109) is the i-th element of Arthur's sequence.



Output



Incorrect sequence" (without the quotes).

n integers — Arthur's favorite sequence. If there are multiple such sequences, print the sequence with the minimum sum|ai|, where |ai| is the absolute value of ai. If there are still several such sequences, you are allowed to print any of them. Print the elements of the sequence without leading zeroes.



Sample test(s)



input



3 2 ? 1 2



output



0 1 2



input



5 1 -10 -9 ? -7 -6



output



-10 -9 -8 -7 -6



input



5 3 4 6 7 2 9



output



Incorrect sequence



显然原题公式可以化为

a[1]<a[k+1]<a[2k+1]...

a[2]<a[k+2]<a[2k+2]...

...

因此贪心填最小的

注意考场上没注意到ai可以填>=1e9的含恨没过PT


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (1000000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n,k;
char s[MAXN];
ll a[MAXN]={0};
bool b[MAXN]={0};
void work(int t,int l,int r)
{
for(int i2=l;i2<=r;i2+=k)
{
a[i2]=t;
t++;
}

}
int main()
{
// freopen("Questions.in","r",stdin);
// freopen(".out","w",stdout);
cin>>n>>k;
For(i,n)
{
scanf("%s",s);
if (s[0]=='?') b[i]=1;
else
{
int len=strlen(s);
bool flag=0;
if (s[0]=='-')
{
For(j,len-1) a[i]=a[i]*10+s[j]-'0';
a[i]=-a[i];
}
else
{
Rep(j,len) a[i]=a[i]*10+s[j]-'0';
}
}
}

// For(i,n) cout<<a[i]<<' '<<b[i]<<endl;

For(i,k)
{
ll p=-2000000000-1;
for(int j=i;j<=n;j+=k)
{
if (!b[j])
{
if (p>=a[j])
{
cout<<"Incorrect sequence"<<endl;
return 0;
}
p=a[j];
}
else
{
int l=j,r=j,tot=1;
ll p2=2000000000+1;
while(j+k<=n)
{
j+=k;
if (!b[j]) {p2=a[j];break;}
else tot++,r=j;
}
if (tot<=p2-p-1)
{
if (p2<=0)
{
int t=p2-1;
for(int i2=r;i2>=l;i2-=k)
{
a[i2]=t;
t--;
}
}
else if (p>=0)
{
work(p+1,l,r);
}
else
{
int suit1=-(tot-1)/2-(tot-1)%2,suit2=-(tot-1)/2;
int pos1=p+1,pos2=p2-tot;
if (pos1<=suit1&&suit1<=pos2)
{
int t=suit1;
for(int i2=l;i2<=r;i2+=k)
{
a[i2]=t;
t++;
}
}
else if (pos1<=suit2&&suit2<=pos2)
{
int t=suit2;
for(int i2=l;i2<=r;i2+=k)
{
a[i2]=t;
t++;
}
}
else if (suit2<=pos1) work(pos1,l,r);
else if (suit1>=pos2) work(pos2,l,r);
}
}
else
{
cout<<"Incorrect sequence"<<endl;
return 0;
}
p=p2;
}
}

}

For(i,n-1) printf("%d ",a[i]);
printf("%d\n",a[n]);




return 0;
}