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 



Sample input:
5 1
1 0 0 1 0


Sample output:
1 2 2 1 2

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K,41)):
    B = [0]*N
    for i in range(N):
        if i-A[i] >= 0:
            B[i-A[i]] += 1
        else:
            B[0] += 1
        if i+A[i]+1 < N:
            B[i+A[i]+1] -= 1
    for i in range(N-1):
        B[i+1] = B[i] + B[i+1]
    if A == B:
        break
    A = B
print(" ".join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K > 50:
    K = 50
for _ in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N-1, i + A[i])
        B[l] += 1
        if (r+1 < N):
            B[r+1] -= 1
    for j in range(1,N):
        B[j] += B[j-1]
    A = copy.copy(B)




for _ in A:
    print(_, end=' ')

Submission status: Time Limit Exceeded

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

for _ in range(K):
    B = [0] * N
    for i, d in enumerate(A):
        l = max(0, i - d)
        r = min(N - 1, i + d)
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
    
    for i in range(1, N):
        B[i] += B[i-1]
    
    A = B.copy()
    if min(A) == N:
        break

print(" ".join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K > 100:
    K = 100
for _ in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N-1, i + A[i])
        B[l] += 1
        if (r+1 < N):
            B[r+1] -= 1
    for j in range(1,N):
        B[j] += B[j-1]
    A = copy.copy(B)




for _ in A:
    print(_, end=' ')

Submission status: Time Limit Exceeded

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

for _ in range(K):
    B = [0] * N
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
    
    for i in range(1, N):
        B[i] += B[i-1]
    
    A = B.copy()
    if min(A) == N:
        break

print(" ".join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import accumulate
input=sys.stdin.buffer.readline

def main():
    n, k = map(int, input().split())
    A = [*map(int, input().split())]
    
    # for _ in range(min(k,int(math.log(n,2)))):
    
    for _ in "_"*k:
        b=[0]*(n)
        
        for i,v in enumerate(A):
            if i>v:
            # b[max(0,i-v)]+=1
                b[i-v]+=1
            else:
                b[0]+=1
            if i+v+1<n:
                b[i+v+1]-=1
        
        # update ans
        # cnt=0
        # for i in range(1,n):
        #     b[i]+=b[i-1]
        A=[*accumulate(b)]
        
        if min(A)==n:
            break
    print(" ".join(map(str,A)))

if '__main__' == __name__:
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))

for i in range(K):
    cum_sum = np.array([0]*N)
    for j in range(N):
        left = max(0, j - A[j])
        right = min(N-1, j+A[j])
        cum_sum[left] += 1
        if right + 1 < N:
            cum_sum[right+1] -= 1
    A[0] = cum_sum[0]
    for j in range(N-1):
        cum_sum[j+1] += cum_sum[j]
        A[j+1] = cum_sum[j+1]

    if A[0] == N and A[N-1] == N:
        break
    
        
for i in range(N):
    print(A[i], " ", end = "")
print()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


b_n, i_k = map(int, input().split())
lamps = np.array([int(x) for x in input().split()])
act = np.zeros(b_n, dtype=np.int64)
def loop(n, k, lamps, act):
    one = np.ones(n, dtype=np.int64)
    init = lamps
    for i in range(k):
        act[:] = 0
        for i in range(n):
            if init[i] == 0:
                continue
            dmin = i - int(init[i])
            dmax = i + int(init[i])
            if dmin < 0:
                dmin = 0
            if dmax > n-1:
                dmax = n-1
            act[dmin:dmax+1] += 1
            act[i] -= 1
        init = act + one
    return init
result = loop(b_n, i_k, lamps, act)
ans = list(map(str,result.tolist()))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(K):
    B = [0]*N
    for i in range(N):
        if i-A[i] >= 0:
            B[i-A[i]] += 1
        else:
            B[0] += 1
        if i+A[i]+1 < N:
            B[i+A[i]+1] -= 1
    for i in range(N-1):
        B[i+1] = B[i] + B[i+1]
    if A == B:
        break
    A = B
print(" ".join(map(str, A)))

Submission status: Time Limit Exceeded

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

for k in range(K):
  B = [0] * N
  for i in range(N):
    s = i - A[i]
    if s < 0:
      s = 0
    l = i + A[i] + 1
    if l >= N:
      l = N
    for j in range(s, l):
      B[j] += 1
  A = B
  if min(A) == N:
    break
    
for b in B:
  print(b, end=" ")

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import accumulate
input=sys.stdin.buffer.readline

def main():
    n, k = map(int, input().split())
    A = [*map(int, input().split())]
    
    # for _ in range(min(k,int(math.log(n,2)))):
    
    for _ in "_"*k:
        b=[0]*(n)
        
        for i,v in enumerate(A):
            b[max(0,i-v)]+=1
            if i+v+1<n:
                b[i+v+1]-=1
        
        # update ans
        # cnt=0
        # for i in range(1,n):
        #     b[i]+=b[i-1]
        A=[*accumulate(b)]
        
        if min(A)==n:
            break
    print(" ".join(map(str,A)))

if '__main__' == __name__:
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))


for _ in range(K):
    B = [0]*N
    if all(e >= N for e in A):
        break
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N-1, i + A[i])
        B[l] += 1
        if (r+1 < N):
            B[r+1] -= 1
    for j in range(1,N):
        B[j] += B[j-1]
    A = copy.copy(B)




for _ in A:
    print(_, end=' ')

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import accumulate
input=sys.stdin.buffer.readline

def main():
    n, k = map(int, input().strip().split())
    A = [*map(int, input().strip().split())]
    
    # for _ in range(min(k,int(math.log(n,2)))):
    
    for _ in "_"*k:
        b=[0]*(n)
        
        for i,v in enumerate(A):
            b[max(0,i-v)]+=1
            if i+v+1<n:
                b[i+v+1]-=1
        
        # update ans
        # cnt=0
        # for i in range(1,n):
        #     b[i]+=b[i-1]
        A=[*accumulate(b)]
        
        if min(A)==n:
            break
    print(" ".join(map(str,A)))

if '__main__' == __name__:
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for i in range(k):
    b = [0] * (n + 1)
    for j in range(n):
        d = a[j]
        l = max(0, j - d)
        r = min(j + d + 1, n)
        b[l] += 1
        b[r] -= 1

    for j in range(n):
        b[j + 1] += b[j]
    b = b[:-1]

    if b == a:
        break
    a = copy.deepcopy(b)
print(*a, sep=' ')

Submission status: Time Limit Exceeded

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

K = min(K, 50)
for _ in range(K):
    B = [0 for _ in range(N)]
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
    
    for i in range(1, N):
        B[i] += B[i-1]
    
    A = B.copy()

print(" ".join(map(str, A)))

Submission status: Time Limit Exceeded

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

dp = [0] * (N + 1)
for k in range(K):
    sta = [max(i-A[i], 0) for i in range(N)]
    end = [min(i+A[i]+1, N) for i in range(N)]
    for s in sta:
        dp[s] += 1
    for e in end:
        dp[e] -= 1
    for i in range(1, len(dp)-1):
        dp[i] += dp[i-1]
    B = dp[:-1]
    if A == B:
        break
    A = B
    dp = [0] * (N + 1)
 
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))


for i in range(K):
    cum_sum = np.array([0]*N)
    for j in range(N):
        left = max(0, j - A[j])
        right = min(N-1, j+A[j])
        cum_sum[left] += 1
        if right + 1 < N:
            cum_sum[right+1] -= 1
    A[0] = cum_sum[0]
    for j in range(N-1):
        cum_sum[j+1] += cum_sum[j]
        A[j+1] = cum_sum[j+1]

    if A[0] == N and A[N-1] == N:
        break
    
        
for i in range(N):
    print(A[i], " ", end = "")
print()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
# import math


b_n, i_k = map(int, input().split())
# tmp = input()
# tmp = list(map(int, input().split()))
# lamps = np.array(tmp, dtype=np.int64)
lamps = np.array([int(x) for x in input().split()])
act = np.zeros(b_n, dtype=np.int64)
def loop(n, k, lamps, act):
    init = lamps
    for i in range(k):
        act[:] = 0
        for i in range(n):
            if init[i] == 0:
                continue
            # d = math.floor(init[i] + 0.5)
            dmin = i - int(init[i])
            dmax = i + int(init[i])
            if dmin < 0:
                dmin = 0
            if dmax > n-1:
                dmax = n-1
            act[dmin:dmax+1] += 1
            act[i] -= 1
        # s = np.sum(act, axis=0)
        init = act + np.ones(n, dtype=np.int64)
    return init
result = loop(b_n, i_k, lamps, act)
ans = list(map(str,result.tolist()))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

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

Submission status: Time Limit Exceeded

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

K = min(K, 100)
for _ in range(K):
    B = [0 for _ in range(N)]
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
    
    for i in range(1, N):
        B[i] += B[i-1]
    
    A = B.copy()

print(" ".join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import accumulate
input=sys.stdin.buffer.readline
def main():
    n, k = map(int, input().strip().split())
    A = [*map(int, input().strip().split())]
    
    # for _ in range(min(k,int(math.log(n,2)))):
    
    for _ in "_"*k:
        b=[0]*(n+1)
        
        for i,v in enumerate(A):
            b[max(0,i-v)]+=1
            b[min(n,i+v+1)]-=1
        
        # update ans
        # cnt=0
        # for i in range(1,n):
        #     b[i]+=b[i-1]
        A=[*accumulate(b)][:-1]
        
        if min(A)==n:
            break
    print(" ".join(map(str,A)))

if '__main__' == __name__:
    main()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
for t in range(K):
  B =[0 for i in range(N)]
  for i in range(N):
    tp=0
    for j in range(N):
      	if abs(i-j) <= A[j]:
        	tp+=1
    B[i] = tp
  A=B
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for i in range(k):
    b = [0] * (n + 1)
    for j in range(n):
        l = max(0, j - a[j])
        r = min(j + a[j] + 1, n)
        b[l] += 1
        b[r] -= 1

    for j in range(n):
        b[j + 1] += b[j]
    b = b[:-1]

    if b == a:
        break
    a = copy.deepcopy(b)
print(*a, sep=' ')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

def main():
    n, k = map(int, input().strip().split())
    A = [*map(int, input().strip().split())]
    
    # for _ in range(min(k,int(math.log(n,2)))):
    
    for _ in "_"*k:
        b=[0]*(n+1)
        
        for i,v in enumerate(A):
            b[max(0,i-v)]+=1
            b[min(n,i+v+1)]-=1
        
        # update ans
        # cnt=0
        # for i in range(1,n):
        #     b[i]+=b[i-1]
        A=[*accumulate(b)][:-1]
        
        if min(A)==n:
            break
    print(" ".join(map(str,A)))

if '__main__' == __name__:
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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



for j in range(K):
    B = np.zeros_like(A)
    for i in range(N):
        fro=max(0,i-A[i])
        to=min(i+A[i],N-1)
        B[fro]+=1
        if to+1 < N:
            B[to+1]-=1
        #print(fro)
        #print(to)
        #print(Alight)
    #print(A)
    A=np.cumsum(B)
    if np.all(A == N):
        break
    #print("------")
    #print(A)

print(" ".join(map(str,A)))

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

def main():
    n, k = map(int, input().strip().split())
    A = [*map(int, input().strip().split())]
    
    # for _ in range(min(k,int(math.log(n,2)))):
    
    for _ in range(k):
        b=[0]*(n+1)
        
        for i,v in enumerate(A):
            b[max(0,i-v)]+=1
            b[min(n,i+v+1)]-=1
        
        # update ans
        # cnt=0
        # for i in range(1,n):
        #     b[i]+=b[i-1]
        A=[*accumulate(b)][:-1]
        
        if min(A)==n:
            break
    print(" ".join(map(str,A)))

if '__main__' == __name__:
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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



for j in range(K):
    B=np.array([0]*(N))
    for i in range(N):
        fro=max(0,i-A[i])
        to=min(i+A[i],N-1)
        B[fro]+=1
        if to+1 < N:
            B[to+1]-=1
        #print(fro)
        #print(to)
        #print(Alight)
    #print(A)
    A=np.cumsum(B)
    if np.all(A == N):
        break
    #print("------")
    #print(A)

print(" ".join(map(str,np.cumsum(B))))

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

def main():
    n, k = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    
    # for _ in range(min(k,int(math.log(n,2)))):
    
    for _ in range(k):
        b=[0]*(n+1)
        
        for i,v in enumerate(A):
            b[max(0,i-v)]+=1
            b[min(n,i+v+1)]-=1
        
        # update ans
        # cnt=0
        # for i in range(1,n):
        #     b[i]+=b[i-1]
        A=[*accumulate(b)][:-1]
        
        if min(A)==n:
            break
    print(" ".join(map(str,A)))

if '__main__' == __name__:
    main()

Submission status: Time Limit Exceeded

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

counts = 0
for i in range(k):
    b = [0] * n
    for j in range(n):
        left = j - a[j] - 0.5
        right = j + a[j] + 0.5
        for k in range(max(0,int(left+1)),min(n,int(right)+1)):
            b[k] += 1
    a = b[:]
    if(a == [n]*n):
        break

print(*a)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
for t in range(K):
  B =[0 for i in range(N)]
  for i in range(N):
    for j in range(N):
      	if abs(i-j) <= A[j]:
        	B[i]+=1
  A=B
print(*A)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

def main():
    n, k = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    
    # for _ in range(min(k,int(math.log(n,2)))):
    
    
    def solve():
        nonlocal A
        for _ in range(k):
            b=[0]*(n+1)
            
            for i,v in enumerate(A):
                b[max(0,i-v)]+=1
                b[min(n,i+v+1)]-=1
            
            # update ans
            # cnt=0
            # for i in range(1,n):
            #     b[i]+=b[i-1]
            A=[*accumulate(b)][:-1]
            
            if min(A)==n:
                break
        print(*A)
    solve()

if '__main__' == __name__:
    main()

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
an = list(map(int, input().split()))


for _ in range(min(k,42)):

    bn = [0] *n
    for i in range(n):
        for j in range(max(i-an[i],0), min(n, i+an[i]+1)):
            bn[j] += 1

    an = bn

print(*an)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K=map(int,input().split())
A=np.array(list(map(int,input().split())),dtype=np.int64)
B=np.zeros(N+1,dtype=np.int64)
if K>41:
  A=np.ones(N,dtype=np.int64)*N
else:
  for k in range(K):
    for i in range(N):
      B[max(0,i-int(A[i]))] +=1
      B[min(N,i+int(A[i])+1)] -=1
    A=np.cumsum(B)[:N]
    B=np.zeros(N+1,dtype=np.int64)

for i in A:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
A = list(map(int,input().split()))
B =[0 for i in range(N)]
for t in range(K):
  for i in range(N):
    for j in range(N):
      	if i >= j-A[j] and i <= j+A[j]:
        	B[i]+=1
  A=B
  B =[0 for i in range(N)]
print(*A)

Submission status: Time Limit Exceeded

Solution code:
#pypy
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.append(0)

#累積和
for _ in range(K):
    B = [0]*(N+1)
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    A,B = B,A
    if min(A) == N:
        break
A.pop()
print(*A)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, k = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    
    # for _ in range(min(k,int(math.log(n,2)))):
    
    
    def solve():
        nonlocal A
        for _ in range(k):
            b=[0]*(n+1)
            
            for i in range(n):
                b[max(0,i-A[i])]+=1
                b[min(n,i+A[i]+1)]-=1
            
            # update ans
            # cnt=0
            for i in range(1,n):
                b[i]+=b[i-1]
            A=b
            if min(A)==n:
                break
        print(*A[:-1])
    solve()

if '__main__' == __name__:
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline()[:-1]


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

for _ in range(k):
    b_li = [0 for _ in range(n)]
    for i in range(n):
        l = max(0, i-a_li[i])
        r = min(n-1, i+a_li[i])
        for j in range(l, r+1):
            b_li[j] += 1
    a_li = b_li
    
print(' '.join(map(str, a_li)))

Submission status: Time Limit Exceeded

Solution code:
#pypy
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.append(0)

#累積和
for _ in range(K):
    B = [0]*(N+1)
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    A = B
    if min(A) == N:
        break
A.pop()
print(*A)

Submission status: Time Limit Exceeded

Solution code:
N , K =map(int,input().split())
A_n =list(map(int,input().split()))


for i in range(min(K,41)):
    B_n =[0 for i in range(N)]
    for j in range(N):
        B_n[max(0 ,j -A_n[j]):min(N ,j + A_n[j]+1)] = map(lambda x : x+1,B_n[max(0 ,j -A_n[j]):min(N ,j + A_n[j]+1)])
    A_n = B_n
print(" ".join(map(str,B_n)))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
A = list(map(int,input().split()))
B =[0 for i in range(N)]
for t in range(K):
  for i in range(N):
    for j in range(N):
      	if i >= j-A[j] and i <= j+A[j]:
        	B[i]+=1
  A=B
  B=[0,0,0,0,0]
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np;

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

for i in range(K):
    tmp = [0] * (N+1)
    for j in range(N):
        left = max(0, j - A[j])
        right = min(N, j + A[j] + 1)

        tmp[left] += 1
        tmp[right] -= 1

    A = np.cumsum(tmp)[:-1]
    if np.all(A == N):
        break

print(' '.join(map(str,A)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K=map(int,input().split())
A=np.array(list(map(int,input().split())))
B=np.zeros(N+1)
if K>41:
  A=np.ones(N)*N
else:
  for k in range(K):
    for i in range(N):
      B[max(0,i-int(A[i]))] +=1
      B[min(N,i+int(A[i])+1)] -=1
    A=np.cumsum(B)[:N]
    B=np.zeros(N+1)

for i in A:
  print(int(i))

Submission status: Time Limit Exceeded

Solution code:
n,k,*a=map(int,open(0).read().split())
if n<=k:
    print(*[n]*n)
    exit()
import copy
for idx in range(k):
    table=[0]*n
    for i in range(n):
        table[max(i-a[i],0)]+=1
        if i+a[i]+1<n:
            table[i+a[i]+1]-=1
    for i in range(1,n):
        table[i]+=table[i-1]
    a=copy.deepcopy(table)
    if a==[n]*n:
        break
print(*a)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=A[:]
for _ in range(K):
    t=[0]*(N+1)
    for i in range(N):
        ti=a[i]
        t[max(0,i-ti)]+=1
        t[min(N,i+ti+1)]-=1
    a=[]
    for i in range(N):
        a.append(t[i])
        if i>0:
            a[i]+=a[i-1]
    if min(a)==N:
        break
print(*a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K=map(int,input().split())
A=np.array(list(map(int,input().split())))
B=np.zeros(N+1)
if K>41:
  A=np.ones(N)*N
else:
  for k in range(K):
    for i in range(N):
      B[max(0,i-int(A[i]))] +=1
      B[min(N,i+int(A[i])+1)] -=1
    A=np.cumsum(B)[:N]
    B=np.zeros(N+1)

for i in list(map(int,A)):
  print(i,end=" ")

Submission status: Time Limit Exceeded

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

def r(i,a):
    x1=i+1-a
    x2=i+2+a
    return [l for l in range(x1,x2) if(l>0 and l-1<N)]

for k in range(K):
    B=[0]*N
    for i in range(N):
        for m in r(i,A[i]):
            B[m-1]+=1
    if(B==A):
        break
    A=B
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
def main():

    import numpy as np

    N,K = map(int,input().split())
    A = np.array(list(map(int,input().split())))
    for _ in range(K):
        B = np.zeros(N,dtype=np.int64)
        for i in range(N):
            l = max(0,i-A[i])
            r = min(N-1,i+A[i])
            B[l] += 1
            if N > r+1:
                B[r+1] -= 1
       
        A = np.cumsum(B)
        if np.all(A==N):
            break

    print(*A)

main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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



for j in range(K):
    Alight=np.array([0]*(N+1))
    for i in range(N):
        fro=max(0,i-A[i])
        to=min(i+A[i],N-1)
        Alight[fro]+=1
        Alight[to+1]-=1
        #print(fro)
        #print(to)
        #print(Alight)
    for i in range(N):
        Alight[i+1]+=Alight[i]
    A=Alight[:]
    if min(Alight) == N:
        break
    #print("------")
    #print(Alight)

print(" ".join(map(str,Alight[:-1])))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
an = list(map(int, input().split()))

for _ in range(min(k,45)):
    bn = [0] *n
    for i in range(n):
        for j in range(max(i-an[i],0), min(n, i+an[i]+1)):
            bn[j] += 1

    an = bn

print(*an)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
# from numba import njit,i8


# @njit(i8[:](i8,i8,i8[:],i8,i8))
def loop(N,K,A,l,r):
    for j in range(K):
        B = np.zeros_like(A)
        for i in range(N):
            l = max(i - A[i],0)
            r = min(i + A[i],N-1)
            B[l] += 1
            if r + 1 < N:
                B[r+1] -= 1
        for i in range(1,N):
            B[i] += B[i-1]
        A = B
    return A


def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A = np.array(A)

    if K >= 43:
        M = 43
    else:
        M = K

    res = loop(N,M,A,0,0)

    print(*res)



main()

Submission status: Time Limit Exceeded

Solution code:
#C
N,K = map(int, input().split())
lights = list(map(int, input().split()))
bright = [0 for i in range(N)]


for kaisuu in range(min(K,45)):
    #すべての電球の明るさがNになったら終わる
    if sum(lights) == N**2:
        break
    for i in range(N):
        count = lights[i]
        for j in range(i-count,i+count+1):
            if 0<=j<=N-1:
                bright[j]+=1
    lights = bright
    bright = [0 for z in range(N)]
        #print(kaisuu,lights)
        #print(kaisuu,bright)
for ans in lights:
    print(ans, end=" ")

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
cntmax=20
while cnt<K:
	B=[0]*N
	if cnt==cntmax:
		break
	for i in range(N):
		l=max(0,i-A[i])
		r=min(N-1,i+A[i])
		B[l]+=1
		if r+1<N:
			B[r+1]-=1
	for i in range(1,N):
		B[i]+=B[i-1]
	cnt+=1
	A=B
print(" ".join(map(str,B)))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
cntmax=40
while cnt<K:
	B=[0]*N
	if cnt==cntmax:
		break
	for i in range(N):
		l=max(0,i-A[i])
		r=min(N-1,i+A[i])
		B[l]+=1
		if r+1<N:
			B[r+1]-=1
	for i in range(1,N):
		B[i]+=B[i-1]
	cnt+=1
	A=B
print(" ".join(map(str,B)))

Submission status: Time Limit Exceeded

Solution code:
def main():

    import numpy as np

    N,K = map(int,input().split())
    A = np.array(list(map(int,input().split())))
    for _ in range(K):
        B = np.zeros(N,dtype=np.int64)
        for i in range(N):
            l = max(0,i-A[i])
            r = min(N-1,i+A[i])
            B[l] += 1
            if N > r+1:
                B[r+1] -= 1
       
        A = np.cumsum(B)
        if np.all(B==N):
            break

    print(*A)

main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
k=min(k,41)

for j in range(k):
    b=np.zeros_like(a)
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    a = np.cumsum(b)
print(" ".join(map(str,a)))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
cntmax=41
while cnt<K:
	B=[0]*N
	if cnt==cntmax:
		break
	for i in range(N):
		l=max(0,i-A[i])
		r=min(N-1,i+A[i])
		B[l]+=1
		if r+1<N:
			B[r+1]-=1
	for i in range(1,N):
		B[i]+=B[i-1]
	cnt+=1
	A=B
print(" ".join(map(str,B)))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
cntmax=42
while cnt<K:
	B=[0]*N
	if cnt==cntmax:
		break
	for i in range(N):
		l=max(0,i-A[i])
		r=min(N-1,i+A[i])
		B[l]+=1
		if r+1<N:
			B[r+1]-=1
	for i in range(1,N):
		B[i]+=B[i-1]
	cnt+=1
	A=B
print(" ".join(map(str,B)))

Submission status: Time Limit Exceeded

Solution code:
from numba import jit
import numpy as np

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

# for _ in range(min(k,int(math.log(n,2)))):

@jit
def solve():
    for _ in range(k):
        start=[0]*n
        end=[0]*n
        
        for i in range(n):
            start[max(0,i-A[i])]+=1
            end[min(n-1,i+A[i])]+=1
    
        # update ans
        cnt=0
        for i in range(n):
            cnt+=start[i]
            A[i]=cnt
            cnt-=end[i]
        if A[0]==n and A[-1]==n:
            break
    return A

print(*solve())

Submission status: Time Limit Exceeded

Solution code:
import copy
import math

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

all_flag = False
for i in range(k):  # 0～k-1
    next_a = [0] * n

    for j in range(len(a)): # 0～n-1個
        strength = a[j] + 0.5
        #print("j-strength = {}".format(j-strength))
        min_index = math.ceil(j-strength)
        if min_index <= 0:
            min_index = 0

        max_index = math.floor(j+strength)
        if max_index >= n:
            max_index = n-1

        #print("{}, {}".format(min_index, max_index))
        for l in range(min_index, max_index+1):
            #print("l = {}".format(l))
            next_a[l] += 1
            if next_a[l] > n:   # これいるかな？
                next_a[l] = n

    a = copy.copy(next_a)

    # check
    all_flag = True
    for l in next_a:
        if l < n:
            all_flag = False
            break
    if all_flag == True:
        print("end.")
        break

b = [str(a) for a in a]
ret = ' '.join(b)
print(ret)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))+[0]
s = [0 for _i in range(n+1)]
for i in range(n):
    s[max(0, i-a[i])] += 1
    s[min(n, i+a[i]+1)] -= 1   
a = s.copy()+[0]
for j in range(min(50, k-1)):
    t = [0 for _i in range(n+1)]
    for i in range(n):
        a[i] += a[i-1]
        t[max(0, i-a[i])] += 1
        t[min(n, i+a[i]+1)] -= 1
    a = t.copy()+[0]
for i in range(1, n):
    a[i] += a[i-1]
print(*a[:n])