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 in Kotlin (1.3.71) (judge verdict: Time Limit Exceeded)

import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


class SegTreeSum(val N: Int) {
    private var sg = LongArray(0)
    private var sg2 = LongArray(0)
    var size = 0
        private set
    init {
        var sz = 1
        while (sz < N) {
            sz = sz shl 1
        }
        this.size = sz
        sg = LongArray(sz shl 1){0}
        sg2 = LongArray(sz shl 1){0}
    }
    fun add(i: Int, j: Int, X: Long, v: Int = 0, l: Int = 0, r:Int = this.size) {
        if (r <= i || j <= l) {
            return
        }
        if (i <= l && r <= j) {
            this.sg2[v] += X
        } else {
            sg[v] += (min(j, r) - max(i, l)) * X
            val m = (l + r) / 2
            add(i, j, X, v * 2 + 1, l, m)
            add(i, j, X, v * 2 + 2, m, r)
        }
    }
    fun add(i: Int, X: Long) {
        add(i, i+1, X)
    }
    fun sum(i: Int, j: Int, v: Int = 0, l: Int = 0, r: Int = this.size): Long {
        if (r <= i || j <= l) {
            return 0L
        } else if (i <= l && r <= j) {
            return sg[v] + (r - l) * sg2[v]
        } else {
            val base = (min(j, r) - max(i, l)) * sg2[v]
            val m = (l + r) / 2
            val vl = sum(i, j, 2 * v + 1, l, m)
            val vr = sum(i, j, 2 * v + 2, m, r)
            return base + vl + vr
        }
    }
}

fun solve() {
    val (N, K) = rd.readListInt()
    val A = rd.readLongArray()

    val B= A.copyOf()
    for (k in 0 until K) {
        val sg = SegTreeSum(N)
        var updating = false

        for (i in 0 until N) {
            sg.add(max(0, i - B[i].toInt()), min(i + B[i].toInt()+1, N), 1L)
        }

        for (i in 0 until N) {
            val b = sg.sum(i, i+1)
            if (B[i] != b) {
                updating = true
                B[i] =b
            }
        }
        if (!updating) break
    }

    val ans = B.joinToString(" ")
    println(ans)
}


//val rd = debug.Reader("etc", "tokiomarine2020", "c", "sample-2")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toInt() } } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toLong() } } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}