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()))
b=a[:]
for i in range(k):
    b=[0 for i in range(n)]
    for j in range(n):
        b=b[:max(j-a[j],0)]+list(map(lambda x:x+1, b[max(j-a[j],0):j+a[j]+1]))+b[j+a[j]+1:]
    #print(b)
    a=b[:]
    m=0
    for j in range(n):
        if a[j]<n:
            m+=1
    if m==0:
        break
    

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()))


def work(lamp_list):
    lamp = [0] * N
    lamp = np.array(lamp)
    for i in range(len(lamp_list)):
        lamp[max(0, i-lamp_list[i]):min(len(lamp_list) - 1, i+lamp_list[i])+1] += 1
    return lamp
lamp_list = A
for _ in range(K):
    lamp_list = work(lamp_list)
for i in lamp_list:
    print(i, end=" ")

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 u in range(max(0,j-a[j]),min(j+a[j]+1,n)):
      b[u]+=1
  a=b    
print(' '.join(map(str,a)))

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()
a = [1] + a
for _ in range(k):
    tmp = copy.copy(a)
    for i in range(1, n + 1):
        idx = []
        c = 0
        for k in range(1, n + 1):
            if k - tmp[k] - 0.5 < i < k + tmp[k] + 0.5:
                c += 1
        a[i] = c

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

Submission status: Time Limit Exceeded

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

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

    a = l[:]

a = list(map(str, a))
print(" ".join(a))

Submission status: Time Limit Exceeded

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

for k in range(K):
    S = [0 for _ in range(N)]
    E = [0 for _ in range(N)]
    for i, b in enumerate(A):
        s = max(0, i-b)
        e = min(N-1, i+b)
        S[s] += 1
        E[e] -= 1

    B = []
    v = 0
    for i in range(N):
        v += S[i]
        B.append(v)
        v += E[i]
    A = B[:]
print(" ".join([str(_) for _ in B]))

Submission status: Time Limit Exceeded

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

i=0
while i<k:
    b=[0]*n
    for j in range(0, n):
        x = a[j]
        y=j-x
        if y<0:
            y=0
        while y<=j+x and y<n :
            b[y]+=1
            y+=1
    a=b
    i+=1

ans = str(a[0])
i=1
while i<n:
    ans +=" "+ str(a[i])
    i+=1
print(ans)

Submission status: Time Limit Exceeded

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

B = [0]*N
for i, a in enumerate(A):
    bottom = i-a
    top = i+a+1
    if bottom < 0:
        bottom = 0
    if top > N:
        top = N
    B[bottom:top] = list(map(lambda x: x+1, B[bottom:top]))

for _ in range(K):
    A = B[:]
    B = [0]*N
    for i, a in enumerate(A):
        bottom = i-a
        top = i+a+1
        if bottom < 0:
            bottom = 0
        if top > N:
            top = N
        B[bottom:top] = list(map(lambda x: x+1, B[bottom:top]))

A = list(map(str, A))
ans = ' '.join(A)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
for l in range(k):
  b=[0]*n
  for i in range(n):
    c=a[i]
    b[i]+=1
    if c>0:
      for j in range(c):
        if (i-c+j)<0 and (i+c-j)>=n:
          continue
        elif (i-c+j)<0:
          b[i+c-j]+=1
        elif (i+c-j)>=n:
          b[i-c+j]+=1
        else:
          b[i-c+j]+=1
          b[i+c-j]+=1
  a=b
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()))
b = np.zeros(3*n)
b[n:2*n] = A.copy()
def update_blightness(b):
    next_b = np.zeros(3*n)
    for i, bi in enumerate(b[n:2*n]):
        add = np.zeros(3*n)
        add[int(n+i-bi):int(n+i+bi+1)] = 1
        next_b += add
    return next_b
for _ in range(k):
    b = update_blightness(b)
ans = list(map(str, map(int, b[n:2*n])))
print(' '.join(ans))

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
    # 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
    for i in range(N):
        A[i] = B[i]
# print(N, K, A, B)
print(" ".join(map(str, B)))

Submission status: Time Limit Exceeded

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

A=list(map(int, input().split()))
for k in range(K):
    B=[0]*(N+1)
    for i in range(N):
        a=A[i]
        start=max(0,i-a)
        end=min(N,i+a+1)
        B[start]+=1
        B[end]-=1
    B=np.array(B)
    B=np.cumsum(B)[:N]
    #print(B)
    A=B.copy()
    if B.min()==N:
        break
print(*B)

Submission status: Time Limit Exceeded

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


for _ in range(K):
    T = [0]*N
    for i in range(N):
        for j in range(max(0,i-A[i]), min(N-1, i+A[i])+1):
            T[j] += 1
    for i in range(N):
        A[i] = T[i];
    
T = [str(i) for i in A]
print(" ".join(T))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-13 21:20:41 +0900
# LastModified: 2020-06-13 21:39:48 +0900
#


import os
import sys
#import numpy as np
#import pandas as pd


def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    a.insert(0,0)
    for _ in range(k):
        mask = [0]*(n+1)
        for zhyo in range(1,n+1):
            sub = a[zhyo]
            mask[zhyo]+=1
            for j in range(1,sub+1):
                if j+zhyo<=n:
                    mask[j+zhyo]+=1
                if zhyo-j>0:
                    mask[zhyo-j]+=1
        a=mask
    
    for i in range(1,n+1):
        print("{} ".format(a[i]),end="")
    print()


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
# Calculate intensity
N, K = [int(v) for v in input().split(" ")]
A_arr = [int(v) for v in input().split(" ")]
step = np.arange(len(A_arr))
def Luminate(A_arr, i):
  isLuminated = np.abs(step - i) < np.array(A_arr)+1
  return isLuminated
def get_Intensity(A_arr):
  return [np.sum(Luminate(A_arr, i)) for i in range(len(A_arr))]
Intensity = A_arr
for i in range(K):
  Intensity = get_Intensity(Intensity)

print(" ".join([str(v) for v in Intensity]))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
for count in range(K):
    area = []
    for i,v in enumerate(A):
        #print(i + 1 - v - 0.5,i + 1 + v + 0.5)
        #l = []
        for i2 in range(int(i + 1 - v - 0.5),int(i + 1 + v + 0.5)):
            #l.append(i2 + 1)
            area.append(i2 + 1)
        #print(l,int(i + 1 - v - 0.5),int(i + 1 + v + 0.5))
    newA = []
    for i,v in enumerate(A):
        newA.append(area.count(i + 1))
    A = newA
print(*A)

Submission status: Time Limit Exceeded

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

import numpy as np
D = np.array([[0]*N]*N)

for k in range(K):
    for i in range(N):
        L = max(0, i-A[i])
        R = min(i+A[i]+1, N)

        D[i][L:R] = 1
    A = D.sum(axis=0)
    
print(*D.sum(axis=0))

Submission status: Time Limit Exceeded

Solution code:
n, k = input().split(" ")
l = input().split(" ")
n = int(n)
k = int(k)
l = [int(c) for c in l]
idx_max = len(l) - 1
for _ in range(k):
    new_l = [0] * (idx_max + 1)
    for i, v in enumerate(l):
        from_idx = max(i - v, 0)
        to_idx = min(i + v, idx_max)
        for j in range(from_idx, to_idx+1):
            new_l[j] = new_l[j] + 1
    l = new_l

print(" ".join([str(i) for i in l]))

Submission status: Time Limit Exceeded

Solution code:

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


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

    A = [i for i in illumi]


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

Submission status: Time Limit Exceeded

Solution code:
def main():
    from sys import stdin
    input = stdin.readline
    # 区間更新・一点取得の加法BIT

    class BIT():
        def __init__(self, n):
            self.n = n
            self.maxbit = 2**(len(bin(n))-3)
            self.bit = [0]*(n+1)

        # 初期化する
        def make_bit(self, a):
            n, bit = self.n, self.bit
            for i, j in enumerate(a):
                x, y = i+1, i+2
                while x < n+1:
                    bit[x] += j
                    x += x & (-x)
                while y < n+1:
                    bit[y] -= j
                    y += y & (-y)

        # 区間[i:j]に値vを足す
        def add(self, i, j, v):
            x, y, n, bit = i+1, j+1, self.n, self.bit
            while x < n+1:
                bit[x] += v
                x += x & (-x)
            while y < n+1:
                bit[y] -= v
                y += y & (-y)

        # 位置iの値を出力する
        def output(self, i):
            ret, x, bit = 0, i+1, self.bit
            while x > 0:
                ret += bit[x]
                x -= x & (-x)
            return ret

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

    for cnt in range(min(k, 42)):
        ans = []
        bit = BIT(n)
        for i in range(n-1, -1, -1):
            bit.add(max(i-a[i], 0), min(i+a[i]+1, n), 1)
        for i in range(n):
            ans.append(bit.output(i))
        a = ans

    print(*ans)


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 = [1] * N
    for j in range(N):
        for k in range(A[j]):
            if j-k-1 >= 0:
                B[j-k-1] += 1
            if j+k+1 <= N-1:
                B[j+k+1] += 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().split()))
for _  in range(k):
  s = 0
  newa = [0 for _ in range(n)]
  for i in range(n):
    d = a[i]
    for j in range(max(0,i-d),min(n-1,i+d)+1):
      newa[j] += 1
      s += 1
  a = newa
  if s == n**2:
    break
for ai in a:
  print(ai,end=" ")

Submission status: Time Limit Exceeded

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

A=list(map(int, input().split()))
for k in range(K):
    B=[0]*(N+1)
    for i in range(N):
        a=A[i]
        start=max(0,i-a)
        end=min(N,i+a+1)
        B[start]+=1
        B[end]-=1
    B=np.array(B)
    B=np.cumsum(B)[:N]
    #print(B)
    A=B.copy()
print(*B)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
#t = int(input())
#print(a)
for _ in range(k):
    nxt = [0] * n
    for i, ai in enumerate(a):
        l = max(0, i - ai)
        r = min(n - 1, i + ai)
        for j in range(l, r + 1):
            nxt[j] += 1
    a = nxt
    if min(a) == n:
        break
print(*a)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(K):
    B = A
    A = [0]*N
    for i in range(N):
        a = B[i]
        L = range(max(0, i-a), min(N, i+a+1))
        for j in L:
            A[j] += 1
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 i in range(K):
  B = [0 for j in range(N)]
  for j in range(N):
    s = A[j]
    # i - A[i] ~ i + A[i]
    for k in range(max(0, j - s), min(j+s+1, N)):
      B[k] += 1
  A = [ B[j] for j in range(N)]
  for j in range(N):
    if A[j] < N:
      break
  else:
    break
print(*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):
        for a in range(A[i] + 1):
            if a == 0:
                B[i] += 1
            else:
                if i + a <= N-1:
                    B[i + a]+= 1
                if i-a >= 0:
                    B[i - a] += 1
    for i in range(N):
        if k != K-1:
            A[i] = B[i]
        else:
            print(B[i], "", end = '')

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
def LI():return list(map(int,input().split()))
def yes():print("YES")
def no():print("NO")
import time
t1=time.time()
n,k=LI()
a=LI()

if k>=n:
    ans=[n]*n
    print(*ans)
    exit()


for _ in range(k):
    b=[0]*n
    for i in range(n):
        q=a[i]
        for j in range(i-q,i+q+1):
            if 0<=j<=n-1:
                b[j]+=1
    a=b[:]
    t2=time.time()
    if t2-t1>1800:
        print(*a)
        exit()
print(*a)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
A2 = [0] * n

for l in range(k):
  for j in range(n):
    for i in range(n):
      if A[i] >= abs(i-j):
        A2[j] += 1
  A = A2
  A2 = [0] * n
  if A == [n]*n:
    break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
ans = [0]*n
#print(ans)
#[0, 0, 0, 0, 0]
for kkk in range(k):
    if kkk == 0:
        for i,l in enumerate(li):
            if l == 0:
                ans[i]+=1
            else:
                mi = max(0,i - l)
                ma = min(n-1,i + l)
                for x in range(mi,ma+1):
                    ans[x]+=1
    else:
        tmp = [0]*n
        for i,l in enumerate(ans):
            if l == 0:
                tmp[i]+=1
            else:
                mi = max(0,i - l)
                ma = min(n-1,i + l)
                for x in range(mi,ma+1):
                    tmp[x]+=1
        ans = tmp
    #print(*ans)
print(*ans)

Submission status: Time Limit Exceeded

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

if(k>=n):
    print(*[n for _ in range(len(a))])
else:
    for h in range(k):
        b=[0 for _ in range(len(a))]
        for i in range(len(a)):
            for j in range(max(0,i-a[i]),min(len(a)-1,i+a[i])+1):
                b[j]+=1
#        print(*b)
        a=b
    print(*a)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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


while k:
    lst=[1]*n
    dic=defaultdict(int)
    cnt=0
    for i in range(n):
        lst[i]+=cnt
        cnt-=dic[i]
        if a[i]>0:
            dic[i+a[i]]+=1
            cnt+=1
    # print(lst)
    dic=defaultdict(int)
    cnt=0
    for i in range(n)[::-1]:
        lst[i]+=cnt
        cnt-=dic[i]
        if a[i]>0:
            dic[i-a[i]]+=1
            cnt+=1
    # print(lst)
    k-=1
    if sum(lst)==n*n:
        break
    # print(k)
    a=lst[:]

print(*lst)

Submission status: Time Limit Exceeded

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

Anew = [0] * N

for iterate in range(K):
    for i, Ai in enumerate(A):
        for j in range(2 * Ai + 1):
            Anewi = i - Ai + j
            if Anewi < 0 or Anewi >= N:
                continue
            Anew[Anewi] += 1
    A = Anew
    Anew = [0] * N

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

Submission status: Time Limit Exceeded

Solution code:
class BinaryIndexedTree(): #1-indexed
    def __init__(self, n):
        self.n = n
        self.tree = [0 for _ in range(n + 1)]

    def sum(self, idx):
        res = 0
        while idx:
            res += self.tree[idx]
            idx -= idx & -idx
        return res

    def add(self, idx, x):
        while idx <= self.n:
            self.tree[idx] += x
            idx += idx & -idx

    def bisect_left(self, x):
        if x <= 0: return 0
        res, tmp = 0, 2**((self.n).bit_length() - 1)
        while tmp:
            if res + tmp <= self.n and self.tree[res + tmp] < x:
                x -= self.tree[res + tmp]
                res += tmp
            tmp >>= 1
        return res + 1

class RAQandRSQ(): #1-indexed, BinaryIndexedTree
    def __init__(self, n):
        self.bit1 = BinaryIndexedTree(n)
        self.bit2 = BinaryIndexedTree(n)

    def add(self, lt, rt, x):
        self.bit1.add(lt, -x * (lt - 1))
        self.bit1.add(rt, x * (rt - 1))
        self.bit2.add(lt, x)
        self.bit2.add(rt, -x)

    def sum(self, lt, rt):
        rsum = self.bit2.sum(rt - 1) * (rt - 1) + self.bit1.sum(rt - 1)
        lsum = self.bit2.sum(lt - 1) * (lt - 1) + self.bit1.sum(lt - 1)
        return rsum - lsum

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

R = RAQandRSQ(N)

for i in range(N):
    R.add(i + 1, i + 2, A[i])

for i in range(K):
    query = []
    for j in range(N):
        s = R.sum(j + 1, j + 2)
        query.append((max(1, j - s + 1), min(N + 1, j + s + 2)))
    R = RAQandRSQ(N + 1)
    for l, r in query:
        R.add(l, r, 1)
    flag = False
    for j in range(N):
        if R.sum(j + 1, j + 2) < N:
            flag = True
    if not flag:
        break

res = [min(R.sum(i + 1, i + 2), N) for i in range(N)]

print(*res)

Submission status: Time Limit Exceeded

Solution code:
def main():
    number, operations = [int(x) for x in input().split()]
    dists = [int(x) for x in input().split()]

    for _ in range(operations):
        dists_new = [0] * number
        for i, d in enumerate(dists):
            start = max(0, i - d)
            end = min(i + d, number - 1)
            for j in range(start, end + 1):
                dists_new[j] += 1
        dists = dists_new
        if min(dists) == number:
            # すべての光が両端まで届く，変化しなくなる。
            break

    print(*dists)


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):
    B = [1]*N
    for i in range(N):
        for j in range(1, A[i]+1):
            if i-j >= 0:
                B[i-j] += 1
            if i+j < N:
                B[i+j] += 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()))
A2 = copy.copy(A)
for i in range(K):
    for t in range(N):
        b = 0
        for j in range(N):
            if t+1 <= (j+1+A[j]+0.5) and (j+1-A[j]-0.5) <= t+1:
                b+=1
        A2[t]=b
    A=copy.copy(A2)

print(*A)

Submission status: Time Limit Exceeded

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

for i1 in range(K):
    B = [0 for i in range(N)]
    for i in range(N):
        for j in range(max(0,i-Lum[i]),min(i+Lum[i]+1,N)):
            B[j]+=1
    Lum = B

Lum = [str(l) for l in Lum]
Lum=" ".join(Lum)
print(Lum)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
A = list(map(int,input().split()))
for _ in range(k):
    c = [0]*n
    for i,j in enumerate(A):
        for k in range(i-j,i+j+1):
            if 0 <= k <= n-1:
                c[k] += 1
    if A == c:
        break
    A = c
print(" ".join(map(str,A)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for _ in range(K):
        if all(a==N for a in A):
            break
        B = list(0 for _ in range(N))
        for i,d in enumerate(A):
            for j in range(max(i-d,0), min(i+d+1,N)):
                B[j] += 1
        A = B[:]
    return ' '.join(map(str,A))

if __name__ == '__main__':
    print(solve())

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
import copy
for k in range(K):
  B = [1 for l in range(N)]
  for i in range(N):
    n = A[i]
    for j in range(1,n+1):
      if i-j>=0:
        B[i-j] += 1
        
      if i+j<=N-1:
        B[i+j] += 1
        
  A = B
A = [str(a) for a in A]
A = ' '.join(A)
print(A)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

A_New_list = [0 for i in range(N)]
for k in range(K):
    for i in range(N):
        for j in range(A_list[i] + 1):
            if j == 0:
                # if A_list[i] != 0:
                A_New_list[i] += 1
            else:
                if i + j < N:
                    A_New_list[i+j] += 1
                if i - j >= 0:
                    A_New_list[i-j] += 1
    # print(A_New_list)
    A_list = A_New_list
    if k != K - 1:
        A_New_list = [0 for n in range(N)]
A_New_list = [str(a) for a in A_New_list]
ans = " ".join(A_New_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = lr()
# ある回数から先は全ての電球にNを足す
for _ in range(K):
    next = [0] * N
    for i in range(N):
        x = A[i]
        for j in range(max(0, i-x), min(N-1, i+x)+1):
            next[j] += 1
    A = next
    if sum(A) == N * N:
        break

print(*A)

Submission status: Time Limit Exceeded

Solution code:
import collections
n,k = map(int, raw_input().split(' '))
ais = map(int ,raw_input().split(' '))
prev = ais
for _ in range(k):

	segments = []
	for i,d in enumerate(ais):
		u = i+1
		segments.append([u-d, u+d])

	for u in range(1, n+1):
		ais[u-1] = 0
		for uu,vv in segments:
			if uu <= u <=vv:
				ais[u-1] += 1
for e in ais:print e,

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=list()
    for j in range(n):
        b.append(0)
    for j in range(n):
        for k in range(max(0,j-a[j]),min(n,j+a[j]+1)):
            b[k]+=1
    a=b
for i in range(n):
    print(a[i],end=" ")

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
for i in range(min(b,int(a**0.5)+4)):
  now=[0]*a
  for j in range(a):
    x=l[j]
    for k in range(max(0,j-x),min(a,j+x+1)):
      now[k]+=1
  l=now
for i in range(a):
  now[i]=min(now[i],a)
print(*now)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, K: int, A: "List[int]"):
    #while True:
    for _ in range(K):
        inc = [0] * N
        dec = [0] * N
        for i in range(N):
            s = max(0, i - A[i])
            e = min(N - 1, i + A[i])
            inc[s] += 1
            dec[e] += 1
        nexts = []
        cur = 0
        for i in range(N):
            cur += inc[i]
            nexts.append(cur)
            cur -= dec[i]
        A = nexts
    print(*A, sep=' ')
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, 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(min(k,1000)):
    s=[0 for _ in range(n)]
    e=[0 for _ in range(n)]
    for i in range(n):
        d=a[i]
        s[max(0,i-d)]+=1
        e[min(n-1,i+d)]+=1
    a[0]=s[0]
    for i in range(1,n):
        s[i]=s[i-1]+s[i]
        e[i]=e[i-1]+e[i]
        a[i]=s[i]-e[i-1]

print(*a)