Problem:
 Score : 500 points    Problem Statement We have N bulbs arranged on a number line, numbered 1 to N from left to right.
Bulb i is at coordinate i .  Each bulb has a non-negative integer parameter called intensity.
When there is a bulb of intensity d at coordinate x , the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5 .
Initially, the intensity of Bulb i is A_i . We will now do the following operation K times in a row:   For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i . Then, change the intensity of each bulb i to B_i .   Find the intensity of each bulb after the K operations.      Constraints  1 \leq N \leq 2 \times 10^5  1 \leq K \leq 2 \times 10^5  0 \leq A_i \leq N         Input Input is given from Standard Input in the following format:  N  K  A_1  A_2  \ldots  A_N       Output Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:  A{'}_1  A{'}_2  \ldots  A{'}_N         Sample Input 1 5 1
1 0 0 1 0      Sample Output 1 1 2 2 1 2  Initially, only Bulb 1 illuminates coordinate 1 , so the intensity of Bulb 1 becomes 1 after the operation.
Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2 , so the intensity of Bulb 2 becomes 2 .       Sample Input 2 5 2
1 0 0 1 0      Sample Output 2 3 3 4 4 3

Solution (Python):
import sys
import numpy as np
from numba import njit

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


@njit('i8[:](i8,i8,i8[:])', cache=True)
def func(n, k, A):
    for _ in range(k):
        B = np.zeros(n + 1, np.int64)
        for i, a in enumerate(A):
            B[max(0, i - a)] += 1
            B[min(i + a + 1, n)] -= 1
        A = B.cumsum()[:-1]
        if np.all(A == n):
            break
    return A


def main():
    N, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)
    ans = func(N, K, A)
    print(*ans)


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(a):
        b = [0]*(n+1)
        for i in range(n):
            l = max(0,i-a[i])
            r = min(n,i+a[i]+1)
            b[l] += 1
            b[r] -= 1
        for i in range(n):
            b[i+1] += b[i]
        return b[:n]
    n,k = LI()
    a = LI()
    while k:
        if sum(a) == n**2:
            break
        a = f(a)
        k -= 1
    print(*a)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
n,k = map(int,input().split())
A = list(map(int, input().split()))

from itertools import accumulate
for i in range(k):
    imos = [0]*(n+1)
    for j in range(n):
        d = A[j]
        l = max(0, j-d)
        r = min(n-1, j+d)
        imos[l] += 1
        imos[r+1] -= 1
    imos = list(accumulate(imos))
    for j in range(n):
        A[j] = imos[j]
    if A == [n]*n:
        break

print(*A)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
c=[0]*n
cnt=0
while cnt<min(k,101):
  cnt+=1
  for i in range(n):
    b[max(0,i-a[i])]+=1
    if i+a[i]<n-1:
      b[i+a[i]+1]-=1
    c[0]=b[0]
  for j in range(n-1):
    c[j+1]=c[j]+b[j+1]
  a=c
  b=[0]*n
  c=[0]*n
print(*a)

Solution (Python):
import math
from itertools import accumulate
n, k = map(int, input().split())
As = list(map(int, input().split()))
for i in range(min(41, k)):
  _As = [0]*(n+1)
  for j in range(n):
    l = max(0, j - As[j])
    r = min(n - 1, j + As[j])
    _As[l] += 1
    _As[r+1] -= 1
  As = list(accumulate(_As))[:-1]
print(' '.join([str(A) for A in As]))

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n, k =map(int,input().split())
    A = list(map(int,input().split())) + [0]
    while k > 0:
        B = [0] * (n + 1) 
        for i, a in enumerate(A):
            B[max(0, i - a)] += 1
            B[min(n, i + a + 1)]  -= 1
        if B[0] == n:
            flag = True
        for i in range(1, n+1):
            B[i] += B[i-1]
            if B[i] != n and i < n:
                flag = False
        A = B[:]
        if flag:
            break
        k -= 1
    print(" ".join(map(str, B[:-1])))

if __name__=='__main__':
    main()

Solution (Python):
n,k=map(int,input().split())
A=list(map(int,input().split()))
C=[n for _ in range(n)]

while k!=0:
    B=[0 for _ in range(n+1)]
    for i,j in enumerate(A):
        B[max(0,i-j)] +=1
        B[min(n,i+j+1)] -=1
    for i in range(1,n):
        B[i] +=B[i-1]
    A=B[:n]
    k -=1
    if A==C:break
print(*A)

Solution (Python):
n,k=map(int,input().split())
A=list(map(int,input().split()))

while k!=0:
    B=[0 for _ in range(n+1)]
    for i,j in enumerate(A):
        B[max(0,i-j)] +=1
        B[min(n,i+j+1)] -=1
    for i in range(1,n):
        B[i] +=B[i-1]
    A=B[:n]
    k -=1
    if sum(A)==n**2:break
print(*A)

Solution (Python):
n,k,*A=map(int,open(0).read().split());e=enumerate
for _ in '_'*min(k,99):
  S=[0]*(n+1)
  B=[0]*(n+1)
  for i,a in e(A):S[max(0,i-a)]+=1;S[min(n,i+a+1)]-=1
  for i,s in e(S[:-1]):B[i+1]=B[i]+s
  A=B[1:]
print(*A)

Solution (Python):
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
for _ in range(K):
    count_list = [0] * N
    for i, v in enumerate(A_list):
        count_list[i - v if i - v > 0 else 0] += 1
        if i + v + 1 < N:
            count_list[i + v + 1] -= 1
    temp = 0
    flag = True
    for i in range(len(A_list)):
        temp += count_list[i]
        if temp != N:
            flag = False
        A_list[i] = temp
    if flag:
        break

print(*A_list)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(K):
    if len(set(A)) == 1 and A[0] == N:
        break
    work = [0] * (N + 1)
    for i in range(N):
        a = A[i]
        idx0 = max(0, i - a)
        idx1 = min(N, i + a + 1)
        work[idx0] += 1
        work[idx1] -= 1
    now = 0
    for i in range(N):
        now += work[i]
        A[i] = now
print(*A)

Solution (Python):
n, k, *a = map(int, open(0).read().split())

for _ in range(k):
    b = [0] * -~n
    for i in range(len(a)):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]

    if all(x == n for x in b[:n]):
        print(*b[:n])
        exit()
    a = b
print(*a[:n])

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(min(K, 50)):
    lamp = [0 for i in range(N + 1)]
    for i in range(N):
        lamp[max(0, i - A[i])] += 1
        lamp[min(N, i + A[i] + 1)] -= 1

    for i in range(1, N + 1):
        lamp[i] += lamp[i - 1]
    A = lamp

[print(A[i], end=' ') for i in range(N)]
print()

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  


N,K = MI()
A = LI()

from itertools import accumulate

for _ in range(min(K,41)):
    B = [0]*(N+1)
    for i in range(N):
        a = A[i]
        B[max(i-a,0)] += 1
        B[min(N,i+a+1)] -= 1
    C = list(accumulate(B))
    A = C

print(*[A[i] for i in range(N)])

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  


N,K = MI()
A = LI()

from itertools import accumulate

for _ in range(min(K,100)):
    B = [0]*(N+1)
    for i in range(N):
        a = A[i]
        B[max(i-a,0)] += 1
        B[min(N,i+a+1)] -= 1
    C = list(accumulate(B))
    A = C

print(*[A[i] for i in range(N)])

Solution (Python):
n,k,*a=map(int,open(0).read().split())
def f(b):
    rt=[0]*-~n
    for i in range(n):
        d=b[i]
        rt[max(0,i-d)]+=1
        rt[min(n,i+d+1)]+=-1
    for i in range(n-1):
        rt[i+1]+=rt[i]
    return rt[:-1]

for i in range(k):
    a=f(a)
    if sum(a)==n**2:
        break
print(*a)

Solution (Python):
n, k, *a = map(int, open(0).read().split())

for _ in range(k):
    b = [0] * -~n
    for i in range(len(a)):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]

    if all(x == n for x in b[:n]):
        print(' '.join(map(str, b[:n])))
        exit()
    a = b
print(' '.join(map(str, a[:n])))

Solution (Python):
import numpy as np
from numba import njit, i8

n, k = map(int, input().split())
arr = np.array(list(map(int, input().split())))


@njit(i8[:](i8, i8, i8[:]), cache=True)
def solve(n, k, arr):
    for i in range(min(k, 50)):
        tmp_arr = np.zeros(n + 1, np.int64)
        for i, power in enumerate(arr):
            tmp_arr[max(0, i - power)] += 1
            tmp_arr[min(n, i + power + 1)] -= 1
        arr = np.cumsum(tmp_arr)[:-1]
    return arr


print(*solve(n, k, arr))

Solution (Python):
import numpy as np
from numba import njit, i8

n, k = map(int, input().split())
arr = np.array(list(map(int, input().split())))


@njit(i8[:](i8, i8, i8[:]), cache=True)
def solve(n, k, arr):
    for i in range(min(k, 50)):
        tmp_arr = np.zeros(n + 2, np.int64)
        for i, power in enumerate(arr):
            tmp_arr[max(0, i - power + 1)] += 1
            tmp_arr[min(n + 1, i + power + 2)] -= 1
        arr = np.cumsum(tmp_arr)[1:-1]
    return arr


print(*solve(n, k, arr))

Solution (Python):
import numpy as np
from numba import njit, i8

n, k = map(int, input().split())
arr = np.array(list(map(int, input().split())))


@njit(i8[:](i8, i8, i8[:]))
def solve(n, k, arr):
    for i in range(min(k, 50)):
        tmp_arr = np.zeros(n + 2, np.int64)
        for i, power in enumerate(arr):
            tmp_arr[max(0, i - power + 1)] += 1
            tmp_arr[min(n + 1, i + power + 2)] -= 1
        arr = np.cumsum(tmp_arr)[1:-1]
    return arr


print(*solve(n, k, arr))

Solution (Python):
import numpy as np
from numba import njit

n, k = map(int, input().split())
arr = np.array(list(map(int, input().split())))


@njit
def solve(n, k, arr):
    for i in range(min(k, 50)):
        tmp_arr = np.zeros(n + 2, np.int64)
        for i, power in enumerate(arr):
            tmp_arr[max(0, i - power + 1)] += 1
            tmp_arr[min(n + 1, i + power + 2)] -= 1
        arr = np.cumsum(tmp_arr)[1:-1]
    return arr


print(*solve(n, k, arr))

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
cnt = 0
while cnt<K:
    B = [0 for _ in range(N+1)]
    for i in range(N):
        a = A[i]
        B[max(i-a,0)] += 1
        B[min(i+a,N-1)+1] -= 1
    for i in range(1,N+1):
        B[i] += B[i-1]
    A = B[:N]
    flag = 0
    for i in range(N):
        if A[i]<N:
            flag = 1
            break
    if flag==0:break
    cnt += 1
print(*A)

Solution (Python):
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def NLI(n):return [[int(i) for i in input().split()] for i in range(n)]
def NLI_(n):return [[int(i)-1 for i in input().split()] for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)]
def RI(a=1,b=10):return random.randint(a,b)
def Rtest(T):
    case,err=0,0
    for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
    print('Tested',case,'case with',err,'errors')
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'
    
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7

inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase

read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()


show_flg=False
show_flg=True

ans=0

n,k=LI()
a=LI()

def f(b):
    rt=[0]*-~n
    for i in range(n):
        d=b[i]
        rt[max(0,i-d)]+=1
        rt[min(n,i+d+1)]+=-1
    for i in range(n-1):
        rt[i+1]+=rt[i]
    return rt[:-1]

for i in range(k):
    a=f(a)
    if sum(a)==n**2:
        break

print(*a)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = list(mapint())
from itertools import accumulate

for _ in range(K):
    lamps = [0]*N
    for i, a in enumerate(As):
        lamps[max(0, i-a)] += 1
        if i+a+1<=N-1:
            lamps[i+a+1] -= 1
    As = list(accumulate(lamps))
    if sum(As)==N**2:
        break
print(*As)

Solution (Python):
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))

def calc_imos(arr):
    imos = [0] * (N + 1)
    for i, a in enumerate(arr):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        imos[l] += 1
        imos[r + 1] -= 1
    new_arr = list(accumulate(imos))[:-1]
    return new_arr


for k in range(K):
    A = calc_imos(A)
    if all([a == N for a in A]):
        print(*([N] * N), sep=' ')
        exit()

print(*A, sep=' ')

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
now = inpl()
for _ in range(k):
    pre = now[::]
    cnt = [0] * (n+1)
    for i in range(n):
        l = max(0, i - pre[i])
        r = min(n, i + pre[i] + 1)
        cnt[l] += 1
        cnt[r] -= 1
    
    now = [0] * n
    now[0] = cnt[0]
    for i in range(1,n):
        now[i] = now[i-1] + cnt[i]
    if min(now) == n:
        break
print(*now)

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))

for _ in range(K):
    imos = [0] * (N+1)
    for i,a in enumerate(A):
        l = max(0, i-a)
        r = min(N, i+a+1)
        imos[l] += 1
        imos[r] -= 1
    for i in range(N):
        imos[i+1] += imos[i]
    imos.pop()
    A = imos
    if all(a==N for a in A): break
print(*A)

Solution (Python):
n,k = map(int, input().split())

al = list(map(int, input().split()))

for _ in range(min(100,k)):
    imos = [0]*(n+1)
    for i,a in enumerate(al):
        l = max(0,i-a)
        r = min(n,i+a+1)
        imos[l] += 1
        imos[r] -= 1
    new_al = []
    curr_val = 0
    for im in imos[:-1]:
        curr_val += im
        new_al.append(curr_val)
    al = new_al[:]

print(*al)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


N,K = MI()
A = LI()

from itertools import accumulate

for _ in range(min(K,100)):
    B = [0]*(N+1)
    for i in range(N):
        a = A[i]
        B[max(i-a,0)] += 1
        B[min(N,i+a+1)] -= 1
    C = list(accumulate(B))
    A = C

print(*[A[i] for i in range(N)])

Solution (Python):
from itertools import accumulate
n, k = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(k):
  B = [0]*(n+1)
  for i, a in enumerate(A):
    B[max(i-a, 0)] += 1
    B[min(i+a+1, n)] -= 1
  A = list(accumulate(B))[:-1]
  if min(A) == n:
    break
print(*A)

Solution (Python):


N,K=map(int,input().split())

A=list(map(int,input().split()))


for _ in range(K):
    ans=[0]*len(A)
    start=[0]*len(A)
    end=[0]*len(A)
    
    for index,item in enumerate(A):
        start[max(0,index-item)]+=1
        end[min(len(end)-1,index+item)]+=1
    
    
    
    
    temp=0
    for i in range(len(ans)):
        temp+=start[i]
        ans[i]=temp
        temp-=end[i]
    
    if A==ans:
        break
    else:
        A=ans[:]

print(*ans)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
  b=[0]*(n+1)
  for i in range(n):
    l=max(0,i-a[i])
    r=min(n,i+a[i]+1)
    b[l]+=1
    b[r]-=1
  for i in range(n-1):
    b[i+1]+=b[i]
  a=b[:n]
print(*a)

Solution (Python):



n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(min(k, 100)):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]
    a = b[:n]
print(" ".join(list(map(str, a))))

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    A = LI()

    
    for _ in range(min(K, 50)):
        tmp = [0] * (N + 1)
        b = [0] * (N + 1)
        for i in range(N):
            tmp[max(i - A[i], 0)] += 1
            tmp[min(i + A[i] + 1, N)] -= 1
        for i in range(N):
            b[i+1] = tmp[i] + b[i]
        for i in range(N):
            A[i] = b[i+1] 
        

    print(*A)

if __name__ == '__main__':
    resolve()

Solution (Python):
import sys
 
import numba as nb
import numpy as np
 
input = sys.stdin.readline
 
 
@nb.njit("i8[:](i8,i8,i8[:])", cache=True)
def solve(N, K, A):
    for _ in range(min(41, K)):
        A_cumsum = np.zeros(shape=N, dtype=np.int64)
        for i in range(N):
            A_cumsum[max(0, i - A[i])] += 1
            b = i + A[i] + 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = np.cumsum(A_cumsum)
    return A
 
 
def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)
 
    ans = solve(N, K, A)
 
    print(" ".join(map(str, ans)))
 
 
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    op = 0
    while True:
        new = [0 for _ in range(n + 1)]
        for i in range(n):
            new[max(0, i - a[i])] += 1
            new[min(n, i + a[i] + 1)] -= 1
        for i in range(1, n + 1):
            new[i] += new[i - 1]
        a = new[:-1]
        op += 1
        if op == k or all(aa == n for aa in a):
            break
    print(" ".join(map(str, a)))


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))


def calc_imos(arr):
    imos = [0] * (N + 1)
    for i, a in enumerate(arr):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        imos[l] += 1
        imos[r + 1] -= 1
    imos = list(accumulate(imos))
    return imos[:-1]


for k in range(min(50, K)):
    A = calc_imos(A)
print(*A, sep=' ')

Solution (Python):
import sys,math,collections,itertools
input = sys.stdin.readline

N,K=list(map(int,input().split()))
A = list(map(int,input().split()))

for i in range(K):
    imo = [0]*(N+1)
    flag = 1
    for j in range(N):
        imo[max(0,j-A[j])] += 1
        imo[min(N,j+A[j]+1)] -= 1
        if j-A[j]>0 or j+A[j]+1<N:
            flag = 0
    A = list(itertools.accumulate(imo))[:-1]
    if flag == 1:
        break
print(*A)

Solution (Python):
N,K = map(int, input().split())
A = list(map(int, input().split()))

for cnt in range(K):
  B = [0] * (N+1)
  for i in range(N):
    bright = A[i]
    l = max(i-bright,0)
    r = min(i+bright+1, N)
    B[l] += 1
    B[r] -= 1
  for i in range(N):
    B[i+1] += B[i]
  
  A = B[:-1]
  
  if min(A) == N:
    
    break
    
print(" ".join(map(str,A)))

Solution (Python):

N, K = map(int, input().split())
X = list(map(int, input().split()))

x = X[:] + [0]
for _ in range(K):
    if all(v == N for v in x[:-1]):
        break

    new = [0] * (N + 1)
    for i in range(N):
        new[max(0, i - x[i])] += 1
        new[min(N, i + x[i] + 1)] -= 1

    for i in range(N):
        new[i + 1] += new[i]
    x = new[:]

print(*x[:-1])

Solution (Python):
from itertools import accumulate

N,K=map(int,input().split())
A=list(map(int,input().split()))

def calc_imos(arr):
  imos=[0]*(N+1)
  for i,a in enumerate(arr):
    l=max(0,i-a) 
    r=min(N-1,i+a) 
    imos[l]+=1
    imos[r+1]-=1
    
  imos=list(accumulate(imos))
  
  return imos[:-1]

for k in range(min(50,K)):
  A=calc_imos(A)
print(*A,sep=" ")

Solution (Python):
from itertools import accumulate

N,K=map(int,input().split())
A=list(map(int,input().split()))

def calc_imos(arr):
  imos=[0]*(N+1)
  for i,a in enumerate(arr):
    l=max(0,i-a) 
    r=min(N-1,i+a) 
    imos[l]+=1
    imos[r+1]-=1
  imos=list(accumulate(imos))
  return imos[:-1]

for k in range(min(50,K)):
  A=calc_imos(A)
print(*A,sep=" ")

Solution (Python):
n,k=map(int, input().split())
a = list(map(int, input().split()))
k = min(k,50)
for i in range(k):
    aa = [0]*n
    for j in range(n):
        aa[max(0,j-a[j])] += 1
        if j+a[j]+1 < n: aa[j+a[j]+1] -= 1
    for j in range(n-1):aa[j+1] = aa[j]+aa[j+1]
    a = aa[:]

print(*a)

Solution (Python):
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(min(50, K)):
    B = [0]*N
    for i in range(N):
        B[max(0, i-A[i])] += 1
        r = i+A[i]+1
        if r < N:
            B[r] -= 1
    A = list(accumulate(B))
print(*A)

Solution (Python):
import numpy as np
from numba import njit, i8


@njit(i8[:](i8, i8, i8[:]), cache=True)
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
from numba import jit, i8


@jit(i8[:](i8, i8, i8[:]), nopython=True, cache=True)
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
from numba import njit


@njit
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
from numba import jit


@jit("i8[:](i8, i8, i8[:])", nopython=True, cache=True)
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
from numba import jit, i8


@jit(i8[:](i8, i8, i8[:]), nopython=True)
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
from numba import jit


@jit("i8[:](i8, i8, i8[:])", nopython=True)
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
from numba import jit


@jit("i8, i8, i8[:]", nopython=True)
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
from numba import jit


@jit
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
from numba import njit


@njit("i8, i8, i8[:]")
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
from numba import jit


@jit("i8, i8, i8[:]")
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    for _ in range(k if k < 60 else 60):
        imos = [0] * (n + 1)
        for i in range(n):
            left = max(0, i - A[i])
            imos[left] += 1
            right = min(n, i + A[i] + 1)
            imos[right] -= 1

        B = list(accumulate(imos))
        A = B
    print(*A[:n])


if __name__ == '__main__':
    resolve()

Solution (Python):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

for _ in range(K):
    flg = True
    imos = [0]*(N+1)
    for i in range(N):
        imos[max(0, i-A[i])] += 1
        imos[min(N, i+A[i]+1)] -= 1
    A = [0]*N
    c = 0
    for i in range(N):
        c += imos[i]
        A[i] = c
        if c != N:
            flg = False
    if flg is True:
        print(*([N]*N), sep=' ')
        exit()


print(*A)