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 k in range(K):
    B = [0] * N
    for i in range(N):
        d = A[i]
        for j in range(-d, d+1):
            index = i + j
            if 0 <= index < N:
                B[index] += 1
    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().strip().split()))


def work(list):
    ans=[]
    for i in range(len(list)):
        count=0
        for j in range(len(list)):
            if i==j:
                count+=1
            else:
                if abs(i-j)<=list[j]:
                    count+=1
        ans.append(count)
    return ans

for i in range(K):
    if i ==0:
        work(A)
        ans=work(A)
    else:
        work(ans)
        ans=work(ans)

print(*ans)

Submission status: Time Limit Exceeded

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

ans = [[0]*n for i in range(k+1)]
ans[0] = a

for i in range(k):
    for j in range(n):
        if j-ans[i][j] >= 0:
            s = j-ans[i][j]
        else:
            s = 0
        if j+ans[i][j]+1 <= n:
            g = j+ans[i][j]+1
        else:
            g = n
        for l in range(s,g):
            ans[i+1][l] += 1

for i in range(n):
    print(ans[k][i], end=" ")

Submission status: Time Limit Exceeded

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

def light(a_list):
    outcome= [0]*n
    for i in range(n):
        for j in range(max(0,i-a_list[i]),min(n,i+a_list[i]+1)):
            outcome[j] += 1
    return outcome

for _ in range(k):
    a = light(a)

[print(aa,end=' ') for aa in a]

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=0
h=0
g=[0]*n
m=[n]*n
while f<k:
    for i in range(n):
        if a[i]+i>=n-1 and i-a[i]<=0:
            g[i]=1
    b=[0]*n
    for i in range(n):
        if g[i]==0:
            for j in range(i - a[i], i + a[i] + 1):
                if 0 <= j <= n - 1:
                    b[j] += 1
        else:
            h+=1

    for i in range(n):
        b[i]+=h
    a=b
    f+=1
    if a==m:
        break
print(*a)

Submission status: Time Limit Exceeded

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

dic = {}
for i, j in enumerate(A, 1):
    dic[i] = j

for l in range(K):

    dic_copy = dic.copy()
    for i in range(1, N + 1):
        dic[i] = 0

    for i, j in dic_copy.items():
        low = i - j
        high = i + j
        for k in range(low, high + 1):
            if k in dic:
                dic[k] += 1

ans = []
for v in dic.values():
    ans.append(v)
ans = map(str, ans)
ans = " ".join(ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#-------------------------------------------------------------------------------
# Name:        module3
# Purpose:
#
# Author:      user
#
# Created:     13/06/2020
# Copyright:   (c) user 2020
# Licence:     <your licence>
#-------------------------------------------------------------------------------

def main():
    n,k = map(int,input().split())
    delighted_counter1 = list(map(int,input().split()))
    delighted_counter2 = [0] * n
    for i,light in enumerate(delighted_counter1):
        left = max(0,i-light)
        right = min(n,i+light+1)
        for j in range(left,right):
            delighted_counter2[j] += 1

    #print(delighted_counter2)
    before = list(delighted_counter2)


    for _ in range(k):
        #print(delighted_counter1)
        delighted_counter1 = list(delighted_counter2)
        delighted_counter2 = [0] * n
        for i,light in enumerate(delighted_counter1):
            left = max(0,i-light)
            right = min(n,i+light+1)
            for j in range(left,right):
                delighted_counter2[j] += 1
        if delighted_counter2 == before:
            delighted_counter1 = list(delighted_counter2)
            break
        before = delighted_counter2

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
N,K = map(int,input().split())
ag = list(map(int,input().split()))
am = [0]*N
for j in range(N):
    m = max(0,j-ag[j])
    M = min(N-1,j+ag[j])
    for k in range(m,M+1):
      am[k] += 1
ak = copy.copy(ag)
ag = copy.copy(am)

for i in range(K-1):
  if ag == [N]*N:
    break
  am = copy.copy(ag)
  for j in range(N):
    #print('ag',ag)
    #print('ak',ak)
    if not (ak[j] >= j and ak[j] >= N-1-j):
      x = max(0,j-ag[j])
      y = max(0,j-ak[j])
      z = min(N-1,j+ak[j])
      w = min(N-1,j+ag[j])
      #print(j,x,y,z,w)
    for k in range(x,y):
      am[k] += 1
    for k in range(z+1,w+1):
      am[k] += 1
    #print(am)
  ak = copy.copy(ag)
  ag = copy.copy(am)
b=[str(i) for i in ag]
b=" ".join(b)
print(b)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n, k = (int(i) for i in input().split(' '))
a = [int(i) for i in input().split(' ')]

for i in range(k):
    b = [0] * n
    for j in range(1, n + 1):
        n1 = j - a[j - 1]
        n2 = j + a[j - 1]
        if n1 < 1:
            n1 = 1
        if n2 > n:
            n2 = n
        b = [b[l - 1] + 1 if n1 <= l and l <= n2 else b[l - 1] for l in range(1, n + 1)]
    a = copy.copy(b)
        
print(' '.join([str(i) for i in a]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

if __name__ == '__main__':
    N, K = map(int, input().strip().split(" "))
    A = np.array(input().strip().split(" ")).astype(int)

    if N <= K:
        print(" ".join([str(N)]*N))
    else:
        for i in range(K):
            B = np.zeros(N).astype(int)
            for j in range(N):
                for k in range(max(0, j - A[j]), min(j + A[j] + 1, N), 1):
                    B[k] += 1
            A = B.copy()
        print(" ".join(A.astype(str)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
# import copy


def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


def sp_xnxn(n=0):
    """
    args:
        int n: a number of lows to read
    example
        input   1
        retrun  [1]

        input   123
        return  [1,2,3]

        input   123
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        return [int(k) for k in xsxs()]
    else:
        return [[int(k) for k in xsxs()] for _ in range(n)]


def xsxs(n=0):
    """
    args:
        int n: a number of lows to read 
    example:
        input   AA
        retrun  AA

        input   A BBB CC
        return  ["A","BBB","CC"]

        input   A BB CCC
                D
        return  [["A","BBB","CC"],
                ["D"]]
    """
    if n == 0:
        temp = list(input().split())
        if len(temp) == 1:
            return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        return [list(input().split()) for _ in range(n)]


def sp_xsxs(n=0):
    """
    args:
        int n: a number of lows to read 
        example:
            input   A
            retrun  ["A"]

            input   ABC
            return  ["A","B","C"]

            input   ABC
                    D
            return  [["A","B","C"],
                    ["D"]]
    """
    if n == 0:
        return [s for s in xsxs()]
    else:
        return [[s for s in xsxs()] for _ in range(n)]


n, k = xnxn()
a = xnxn(flag="l")
a = np.array([1] + a)
for _ in range(k):
    add = np.zeros(n+1, dtype="int")
    for i in range(1, n + 1):
        idx_min = max(1, i - a[i])
        idx_max = min(n, i + a[i])
        add[idx_min:idx_max + 1] += 1
    a = add


for i in a[1:]:
    print(i, end=" ")

Submission status: Time Limit Exceeded

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

lamp = []
for i in range(len(A)):
    lamp.append(A[i])

def operation(lampList):
    tmpList = [0] * len(lampList)

    for i in range(len(lampList)):
        l = lampList[i] + 1
        if (l < NK[0]):
            tmpList[i] += 1
        for j in range(1, l):
            if (i - j >= 0):
                tmpList[i - j] += 1
            if (i + j < NK[0]):
                tmpList[i + j] += 1
    return tmpList

for i in range(NK[1]):
    lamp = operation(lamp)

L=[str(a if a < NK[0] else NK[0]) for a in lamp]
L=" ".join(L)
print(L)

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):
    tmp_li = [y for i, x in enumerate(a_li) for y in range(max(0, i-x), min(i+x+1, n), 1)]
    a_li = [tmp_li.count(i) for i in range(n)]
print(' '.join(map(str, a_li)))

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):
    b[max(0, i-a[i]):min(n, i+a[i]+1)] += 1
  a = b
  if np.count_nonzero(a == n) == n:
    break
print(" ".join(list(map(str, a))))

Submission status: Time Limit Exceeded

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

    for _ in range(k):
        num = [0]*n
        for _2 in range(n):
            min = _2 - a[_2] if 0 < _2 - a[_2] - 0.5 else 0
            max = _2 + a[_2] if n > _2 + a[_2] + 0.5 else n-1
            for _3 in range(min, max+1):
                num[_3] += 1

        a = num

    for n in a:
        print(n, end=" ")

Submission status: Time Limit Exceeded

Solution code:
# C - Lamps
N,K = map(int,input().split())
A = list(map(int,input().split()))
for k in range(K):
    new_A = [0]*N
    for i in range(N):
        s = max(0,i-A[i])
        t = min(N,i+A[i]+1)
        new_A[s:t] = [x+1 for x in new_A[s:t]]
    A = new_A[:]
    if min(A)==N:
        break
for i in range(N):
    print(A[i],end=' ')
print('\n')

Submission status: Time Limit Exceeded

Solution code:
import sys

nb, k = map(int, input().split())
lst = [int(n) for n in input().split()]

# 1 0 0 1 0
# 1 2 2 1 2
# 3 3 4 4 3
# 5 5 5 5 5


def clamp(a, b, c):
    return sorted([a, b, c])[1]


for _ in range(k):
    new = [0] * len(lst)
    for i, n in enumerate(lst):
        for j in range(max(0, i - n), min(i + n + 1, len(lst))):
            new[j] += 1

    if new == lst:
        print(*new)
        break
    lst = new
else:
    print(*lst)

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())))
B0 = np.array([0] * N)
for k in range(K):
    B = B0.copy()
    # print(N, K, A, B)
    for i in range(N):
        a = A[i]
        left = max(i - a, 0)
        right = min(i + a + 1, N)
        # print(i, left, right)
        for j in range(left, right):
            B[j] += 1
    A = B.copy()
    if min(B) >= N:
        break
# print(N, K, A, B)
print(" ".join(map(str, B)))

Submission status: Time Limit Exceeded

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

a = [0] * N
for k in range(K):
    for i in range(N):
        a[max(0, i - A[i])] += 1
        if N - 1 >= (A[i] + i + 1):
            a[A[i] + i + 1] -= 1

    if a[0] == N:
        A = [N] * N
        break
    for j in range(N):
        A[j] = A[j - 1] if j > 0 else 0
        A[j] += a[j]
        a[j] = 0
    # print("k=", k, A)


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

Submission status: Time Limit Exceeded

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

for k in range(K):
    counterlist = np.array([0]*N)
    for i in range(N):
        d = A[i]
        u = max(0,i-d)
        v = min(N-1,i+d)
        counterlist[u:v+1]+=1
    A = counterlist
    if set(A)==1:
        print(A)
        break
        

else:
    print(*A)

Submission status: Time Limit Exceeded

Solution code:
import math
from itertools import accumulate
import sys

def input():
    return sys.stdin.readline().strip()

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

    for _ in range(K):
        data = [0] * len(A)
        for i in range(N):
            range_mai = math.ceil(i - A[i] - 0.5)
            range_pura = math.floor(i + A[i] + 0.5)
            if range_mai < 0:
                range_mai = 0
            if range_pura > N - 1:
                range_pura = N - 1
            data[range_mai] += 1
            if range_pura + 1 != N:
                data[range_pura + 1] -= 1
            
        ruiseki = list(accumulate(data))
        A = ruiseki
        if min(A) == N:
            break
    print(*A)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for _ in range(K):
  newA=[0]*N
  for i,a in enumerate(A):
    for j in range(i - a, i + a + 1):
      if j < 0:
        continue
      if j >= N:
        break
      newA[j]+=1
  A=newA

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

Submission status: Time Limit Exceeded

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

    for i in range(K):
        imos = [0] * (N + 1)
        for j in range(N):
            # s = A[j]
            l, r = max(0, j - A[j]), min(j + A[j], N - 1)
            # print("l,r,s = {} {} {}".format(l, r, s))
            imos[l] += 1
            imos[r + 1] -= 1
        for k in range(N):
            imos[k + 1] = imos[k] + imos[k + 1]
        A = imos[:N]

    print(*imos[:N])


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def add(o):
    return o + k - i - 1

for i in range(k):
  a_c = [0 for y in range(n)]
  for j in range(n):
    ax = a[j]
    for m in range(-ax, ax+1):
      if j+m >= 0 and j+m < n:
        a_c[j+m] += 1
  a = a_c
  if min(a) >= n:
    a = list(map(add, a))
    break

print(*a)

Submission status: Time Limit Exceeded

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

i=0
while i<K:
    j=0
    B=[1]*N
    while j<N:
        B[j+1:j+A[j]+1]=[a+1 for a in B[j+1:j+A[j]+1]]
        B[max(0,j-A[j]):j]=[a+1 for a in B[max(0,j-A[j]):j]]
        j+=1
    A=B
    if A==[N]*N:
        break
    i+=1

print(*A)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K = map(int,input().split())
res = list(map(int,input().split()))
# res = [0]*N
for k in range(K):
    delta = np.zeros((N+1), dtype=np.int32)
    for i,val in enumerate(res):
        left = max(0, i-val)
        right = min(N, i+val+1)
        delta[left] += 1
        delta[right] -= 1
    res = np.cumsum(delta, dtype=np.int32)[:N]
    # print(k)
    if delta[0] == -delta[N] == N:
        break
print(*res)

Submission status: Time Limit Exceeded

Solution code:
import math


N,K=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
Atemp=[0 for i in range(len(A))]
#print(Atemp)
flag=1
for i in range(K):
    for j in range(1,len(A)):
        start=max(1,j-A[j])
        end=min(len(A),j+A[j]+1)
        for k in range(start,end):
            Atemp[k]+=1

    """
    for l in range(1,int(len(A)/2)):

        if Atemp[l]>abs(len(A)-l):
            flag*=1
        else:
            flag*=0

    for l in range(int(len(A)/2),len(A)):
        if Atemp[l]>l:
            flag*=1
        else:
            flag*=0

    """
    flag=1
    for l in range(1,len(A)):
        if Atemp[l]>=len(A)-1:
            flag*=1
        else:
            flag*=0
    if flag==1:
        A=Atemp.copy()
        break
    A=Atemp.copy()
    Atemp = [0 for p in range(len(A))]
    """
    if flag==1:
        for o in range(1,len(A)):
            A[o]+=(K-i+1)*len(A)
            print(o)
        break
    flag=1
    """

    #print(A)
for m in range(1,len(A)):
    print(A[m],end=" ")

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop

n, k = [int(v) for v in input().split()]
init_lamps = [int(v) for v in input().split()]


def step(lamps):
    new = [1 for _ in range(len(lamps))]
    heap = []
    for i, v in enumerate(lamps):
        while len(heap) > 0 and heap[0] < i:
            heappop(heap)
        new[i] += len(heap)
        if v > 0:
            heappush(heap, i + v)
    heap = []
    for i, v in enumerate(reversed(lamps)):
        while len(heap) > 0 and heap[0] < i:
            heappop(heap)
        new[n - i - 1] += len(heap)
        if v > 0:
            heappush(heap, i + v)
    return new


lamps = init_lamps
for _ in range(k):
    lamps = step(lamps)

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np
import copy

def main():
    N, K = map(int, input().split())
    A = np.fromstring(input(), 'int', sep=' ')
    B = np.zeros_like(A)

    for i in range(K):
        for j in range(N):
            min_ = max(0, (j) - A[j])
            max_ = min(N, (j) + A[j])
            B[min_: max_ + 1] += 1
        A = copy.deepcopy(B)
        B[:] = 0
    for i in A:
        print(i, end=' ')
    print('')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

bef = copy.copy(A)
aft = [0 for _ in range(n)]
aft_array = np.array(aft)

for k in range(K):
    for i in range(n):
        a = bef[i]
        aft_array[max(0, i-a):min(n-1, i+a)+1]+=1
    if bef ==  aft_array.tolist():
        break
    bef = aft_array.tolist()
    aft = [0 for _ in range(n)]
    aft_array = np.array(aft)
print(*bef)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a_in = list(map(int, input().split()))
diff_list = [0 for num in range(n)]
diff_list[0] = a_in[0]
for i in range(1, n):
    diff_list[i] = a_in[i] - a_in[i-1]


for i in range(k):
    new_list = [0 for num in range(n)]
    d_sum = 0
    for j, d in enumerate(diff_list):
        d_sum += d
        if j-d_sum > 0:
            new_list[j-d_sum] += 1
        else:
            new_list[0] += 1
        if d_sum+j+1 < n:
            new_list[j+d_sum+1] -= 1
    # print(new_list)
    diff_list = new_list.copy()

ans = 0
for d in diff_list:
    ans += d
    print(ans, end= ' ')

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
width = [0 for _ in range(N)]
cnt = 0
for k in range(K):
    for i in range(N):
        if i-A[i]-0.5 < 0:
            left = int(i-A[i]-0.5)
        else:
            left = int(i-A[i]-0.5) + 1
        right = int(i+A[i]+0.5)
        if left < 0:
            left = 0
        if right > N-1:
            right = N - 1
        if left == 0 and right == len(A):
            cnt += 1
        width[left:right+1] = map(lambda x: x+1, width[left:right+1])
    A = width.copy()
    if cnt == N:
        break
    width = [0 for _ in range(N)]

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

def main():
    N,K = inpl()
    Als = inpl()

    up = [0]+ Als
    """for k in range(1,len(up)):
        up[k] += (K-1)"""
    for _ in range(K):
        uup = [0]*(N+1)
        for i,strong in enumerate(up):
            if i != 0:
                a = max(0,i-strong)
                b = min(N+1,i+strong+1)
                for kk in range(a,b):
                    uup[kk] += 1
        up = uup
    res = ' '.join(map(str,up[1:]))
    print(res)

main()

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
Ai = input().split()
Bi = [int(i) for i in Ai]

if K >= N:
    for i in range(N):
        print(N)
else:
    for n in range(K):
        li = [0 for i in range(N)]
        for i,x in enumerate(Bi):
            li[i] += 1
            for l in range(1,x+1):
                if i - l >= 0:
                    li[i-l] += 1
                if i + l <= N - 1:
                    li[i+l] += 1
        Bi = li
    for i in li:
        print(i)

Submission status: Time Limit Exceeded

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

for i in range(K):
    Count = [0 for j in range(N)]
    
    for k in range(1,N+1):
        for l in range(max(1,k-Light[k-1]),min(N+1,k+Light[k-1]+1)):
            Count[l-1] += 1
            
    Light = Count

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

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
old=[-1]*n
def hantei(a,b):
    for i in range(n):
        if a[i] != b[i]:
            return False
    return True

for _ in range(k):
    if hantei(a,old):
        break
    temp = [0]*n
    for i in range(n):
        start,goal = i-a[i], i+a[i]+1
        for j in range(start,goal):
            if 0<=j<n:
                temp[j]+=1
    old=a[:]
    a=temp[:]

for val in a:
    print(val, end=" ")

Submission status: Time Limit Exceeded

Solution code:
import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush
import collections

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


for i in range(k):
    nw=[0]*n
    for x,d in enumerate(a):
        l=x-d-0.5
        r=x+d+0.5

        for p in range(n):
            if p>=l and p<=r:
                nw[p]+=1
    f=1
    for i in range(n):
        if a[i]==nw[i]:
            f=1
        else:
            f=0
            break
    if f:
        break
    a[:]=nw

for i in a:
    print(i,end=" ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def count_num_light(a):
  ret = np.array([0 for _ in range(len(a))])
  for i in range(len(a)):
    start = max(0, i-a[i])
    ret[start:i+a[i]+1] += 1
  
  return ret
                  
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
num_light = count_num_light(a)

for i in range(k-1):
  num_light = count_num_light(num_light)

print(*num_light)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
array = list(map(int, input().split()))
Array = [0]*n
def plusone(n):
    return n + 1

for j in range(k):
    for i in range(n):
        ai = array[i]
        Array[max(i-ai, 0):min(i+ai+1,n+1)] = map(plusone, Array[max(i-ai, 0):min(i+ai+1,n+1)])
        if j == k - 1:
            answer = Array
    array = Array
    Array = [0] * n

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

Submission status: Time Limit Exceeded

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

def getmask(N,i):
  mask = list(range(i))[::-1] + list(range(N-i))[1:]
  return np.array(mask)
mask = [getmask(N+1,i) for i in range(1,N+1)]


for k in range(K):
  akarusa = [np.array(A)-i for i in mask]
  nextA = [len([i for i in j if i>=0]) for j in akarusa]
  A = nextA
print(" ".join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N, K = next(it), next(it)
    A = [next(it) for i in range(N)]

    for k in range(K):
        B = [0]*N
        for i, di in enumerate(A):
            for j in range(max(0, i-di), min(i+di+1,N)):
                B[j] += 1
        A = B
        if all(a == N for a in A):
            break
    print(*A)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from sys import setrecursionlimit
import numpy as np

setrecursionlimit(10 ** 7)

n,k = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
a = np.array(a,dtype=np.int64)
lamp= np.zeros(n,dtype=np.int64)
#a = np.array([(10**5)*2]*((10**5)*2))
#n = (10**5)*2

for i,j in enumerate(a):
    lamp[max(0,i-j):min(n+1,i+j+1)] += 1

if k == 1:
    print(*lamp)
    exit()

for _ in range(min(k-1,6)):
    b = np.zeros(n,dtype=np.int64)
    for i,j in enumerate(lamp):
        b[max(0,i-j):min(n+1,i+j+1)] += 1
    b[b>n] = n
    lamp = b.copy()

lamp[lamp>n] = n

print(*lamp)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

    
N, K = mi()
A = li()

#light = [0] * (N+2)
#A = [0] + A + [0]

for i in range(K):
    new = [0] * (N+1)
    for j in range(N):
        new[max(j-A[j], 0)] += 1
        new[min(j+A[j]+1, N)] += -1
        #print(new)
    new = list(accumulate(new))
    A = new[:N]
    if sum(A) == N **2:
        for i in range(N):
            print(N, '', end='')
        print()
        exit()
    #print(tmp)

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

Submission status: Time Limit Exceeded

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

for _ in range(K):
    answer = [0 for _ in range(N)]
    for i in range(N):
        minus_area = (i + 1) - A[i] - 0.5
        plus_area = (i + 1) + A[i] + 0.5
        if minus_area < 0.5:
            minus_area = 0.5
        if plus_area > N + 0.5:
            plus_area = N + 0.5
        minus_area += 0.5
        plus_area -= 0.5
        for index in range(int(minus_area) - 1, int(plus_area)):
            answer[index] += 1
    A = answer

for a in answer:
    print(a, end=" ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int, input().split())
d = np.array(list(map(int, input().split())))
l = np.arange(n)

def func(x_left, x_right):
  for i in range(n):
    temp_left = x_left[i]
    temp_right = x_right[i]
    if temp_left < 0:
      temp_left = 0
    if temp_right < 0:
      temp_right = n
    ans[temp_left:temp_right] += 1

for _ in range(k):
  ans = np.array([0]*n)
  x_left = l-d
  x_right = l+d+1
  func(x_left, x_right)
  d = ans.copy()

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

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())))
new_A = A
len_A=len(A)
count_list = np.zeros(len_A, dtype = int)
K_list=range(K)
A_list=range(len_A)
for i in K_list:
    for j in A_list:
        if(new_A[j]!=0):
            low_posi=j-new_A[j]
            if(low_posi<0):
                low_posi=0
            high_posi = j+new_A[j]
            if(high_posi>len_A):
                high_posi=len_A
            count_list[low_posi:high_posi+1] += 1
        else:
            count_list[j]+=1
    new_A=count_list
    count_list = np.zeros(len_A,dtype=int)
for s in new_A:
  print(str(s)+" ", end ="")
print("")

Submission status: Time Limit Exceeded

Solution code:
import sys

rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, k = rm()
a = rl()
for _ in range(k):
  li = [0] * n
  for i in range(n):
    s = max(i - a[i], 0)
    e = min(i + a[i], n-1)
    for m in range(s, e+1):
      li[m] += 1
  a = li
for v in a:
    print(v, end=' ')

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=[0 for e in range(n)]
for _ in range(k):
    for i in range(len(a)):
        if(i-a[i]>=0):
            if(i+a[i]<n):
                ans[i-a[i]:i+a[i]+1]=map(lambda x: x+1, ans[i-a[i]:i+a[i]+1])
            else:
                ans[i-a[i]:n]=map(lambda x: x+1, ans[i-a[i]:n])
        else:
            if(i+a[i]<n):
                ans[0:i+a[i]+1]=map(lambda x: x+1, ans[0:i+a[i]+1])
            else:
                ans[0:n]=map(lambda x: x+1, ans[0:n])

    a=ans
    ans=[0 for e in range(n)]
for h in range(len(a)):
    print(a[h],end = " ")