Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Sliding Minimum Element

  For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $L$, find the minimum of each possible sub-arrays with size $L$ and print them from the beginning. For example, for an array $\{1, 7, 7, 4, 8, 1, 6\}$ and $L = 3$, the possible sub-arrays with size $L = 3$ includes $\{1, 7, 7\}$, $\{7, 7, 4\}$, $\{7, 4, 8\}$, $\{4, 8, 1\}$, $\{8, 1, 6\}$ and the minimum of each sub-array is 1, 4, 4, 1, 1 respectively.

Constraints

 $1 \leq N \leq 10^6$ 

 $1 \leq L \leq 10^6$

 $1 \leq a_i \leq 10^9$

 $L \leq N$ 

Input

The input is given in the following format.

$N$ $L$

$a_1$ $a_2$ ... $a_N$

Output

  Print a sequence of the minimum in a line. Print a space character between adjacent elements.

Sample Input 1

7 3
1 7 7 4 8 1 6

Sample Output 1

1 4 4 1 1



Sample input:
7 3
1 7 7 4 8 1 6


Sample output:
1 4 4 1 1

Submission status: Runtime Error

Solution code:
class Node:
    def __init__(self, x):
        self.data = x
        self.left = None
        self.right = None
        self.balance = 0

def rotate_right(node):
    lnode = node.left
    node.left = lnode.right
    lnode.right = node
    return lnode

def rotate_left(node):
    rnode = node.right
    node.right = rnode.left
    rnode.left = node
    return rnode

def search(node, x):
    while node is not None:
        if node.data == x: return True
        if x < node.data:
            node = node.left
        else:
            node = node.right
    return False

def update_balance(node):
    if node.balance == 1:
        node.right.balance = -1
        node.left.balance = 0
    elif node.balance == -1:
        node.right.balance = 0
        node.left.balance = 1
    else:
        node.right.balance = 0
        node.left.balance = 0
    node.balance = 0

LEFT  = 0
RIGHT = 1

def balance(root, path):
    new_node = None
    while len(path) > 0:
        pnode, dir = path.pop()
        if dir == LEFT:
            pnode.balance += 1
        else:
            pnode.balance -= 1
        b = pnode.balance
        if b == 0: return root
        if b > 1:
            if pnode.left.balance < 0:

                pnode.left = rotate_left(pnode.left)
                new_node = rotate_right(pnode)
                update_balance(new_node)
            else:

                new_node = rotate_right(pnode)
                new_node.balance = 0
                pnode.balance = 0
            break
        elif b < -1:
            if pnode.right.balance > 0:

                pnode.right = rotate_right(pnode.right)
                new_node = rotate_left(pnode)
                update_balance(new_node)
            else:

                new_node = rotate_left(pnode)
                new_node.balance = 0
                pnode.balance = 0
            break

    if len(path) > 0:

        gnode, gdir = path.pop()
        if gdir == LEFT:
            gnode.left = new_node
        else:
            gnode.right = new_node
    elif new_node is not None:
        return new_node
    return root


def insert(root, x):
    if root is None: return Node(x)
    path = []
    node = root
    while True:
        if node.data == x: return root
        elif x < node.data:
            path.append((node, LEFT))
            if node.left is None:
                node.left = Node(x)
                break
            node = node.left
        else:
            path.append((node, RIGHT))
            if node.right is None:
                node.right = Node(x)
                break
            node = node.right
    return balance(root, path)

def balance_delete(root, path):
    while len(path) > 0:
        new_node = None
        pnode, dir = path.pop()
        if dir == LEFT:
            pnode.balance -= 1
        else:
            pnode.balance += 1
        b = pnode.balance
        if b > 1:
            if pnode.left.balance < 0:

                pnode.left = rotate_left(pnode.left)
                new_node = rotate_right(pnode)
                update_balance(new_node)
            else:

                new_node = rotate_right(pnode)
                if new_node.balance == 0:
                    new_node.balance = -1
                    pnode.balance = 1
                else:
                    new_node.balance = 0
                    pnode.balance = 0
        elif b < -1:
            if pnode.right.balance > 0:

                pnode.right = rotate_right(pnode.right)
                new_node = rotate_left(pnode)
                update_balance(new_node)
            else:

                new_node = rotate_left(pnode)
                if new_node.balance == 0:
                    new_node.balance = 1
                    pnode.balance = -1
                else:
                    new_node.balance = 0
                    pnode.balance = 0
        elif b != 0:
            break

        if new_node is not None:
            if len(path) == 0: return new_node
            gnode, gdir = path[len(path) - 1]
            if gdir == LEFT:
                gnode.left = new_node
            else:
                gnode.right = new_node
            if new_node.balance != 0: break
    return root

def _search(node, x, path):
    while node is not None:
        if node.data == x: return node
        if x < node.data:
            path.append((node, LEFT))
            node = node.left
        else:
            path.append((node, RIGHT))
            node = node.right
    return None

def _search_min(node, path):
    while node.left is not None:
        path.append((node, LEFT))
        node = node.left
    return node

def delete(root, x):
    if root is None: return None
    path = []
    node = _search(root, x, path)
    if node is None: return root
    if node.left is not None and node.right is not None:

        path.append((node, RIGHT))
        min_node = _search_min(node.right, path)
        node.data = min_node.data
        node = min_node
    if len(path) > 0:
        pnode, dir = path[len(path) - 1]
    else:
        pnode = None

    if node.left is None:
        cnode = node.right
    else:
        cnode = node.left
    if pnode is None:
        return cnode
    elif dir == LEFT:
        pnode.left = cnode
    else:
        pnode.right = cnode
    return balance_delete(root, path)
            
[N,L] = [int(x) for x in input().split()]
A = [[int(x),int(i)] for i,x in enumerate(input().split())]
Tree = None
for i in range(L) : Tree = insert(Tree,A[i])
ANS = [str(search_min(Tree)[0])]

for i in range(L,N):
    Tree = delete(Tree, A[i-L])
    Tree = insert(Tree, A[i])
    ANS.append(str(search_min(Tree)[0]))
    
print(" ".join(ANS))

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = dict
ANS = [10**9+1]*N
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    try : A[x] += [i]
    except KeyError : A[x] =  [i]
for i in set(A) :
    for j in A[i] :
        for k in range(L) :
            try :
                if ANS[j+k] == 10**9+1 : 
                    ANS[j+k] = i
                    count += 1
            except IndexError : continue
    if count == N : break
for i in ANS[L-1:-1]:
    print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {10**9+1:1}
ANS = [10**9+1]*N
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    try : A[x] += [i]
    except KeyError : A[x] =  [i]
for i in set(A) :
    for j in A[i] :
        for k in range(L) :
            try :
                if ANS[j+k] == 10**9+1 : 
                    ANS[j+k] = i
                    count += 1
            except IndexError : continue
    if count == N : break
for i in ANS[L-1:-1]:
    print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {10**9+1:1}
ANS = [10**9+1]*N
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    try : A[x] += [i]
    except KeyError : A[x] =  [i]
for i in set(A) :
    for j in A[i] :
        for k in range(L) :
            try :
                if ANS[j+k] == 10**9+1 : 
                    ANS[j+k] = i
                    count += 1
            except IndexError : continue
        if count == N : break
for i in ANS[L-1:-1]:
    print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count >= N : break
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count > N + 2 : break

if L = 1 :
    for i in range(L-1,N-2) : print(ANS[i], end=" ")
    print(ANS[N-1])
else :
    for i in range(L-1,N-1) : print(ANS[i], end=" ")
    print(ANS[N])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count > N + 2 : break

if L == 1 :
    for i in range(L-1,N-1) : print(ANS[i], end=" ")
    print(ANS[N-1])
else :
    for i in range(L-1,N-1) : print(ANS[i], end=" ")
    print(ANS[N-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count > N + 2 : break
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count >= N : break
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count > N + 10 : break
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count > N + 30 : break
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS && j + k < N:
                ANS[j+k] = i
                count += 1
    if count == N : break

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

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS && j + k < N:
                ANS[j+k] = i
                count += 1
    if count > N : break

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

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS && j + k < N:
                ANS[j+k] = i
                count += 1
    if count > N + 1 : break

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

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
B = [True]*N
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B[i] = x
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if (N-count)**2 < N : break

for i in range(N):
    if i not in ANS:
        ANS[i] = min(B[i+1-L:i+1])
        
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
B = [True]*N
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B[i] = x
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if (N-count)**2 < N : break

for i in range(N):
    if i not in ANS:
        try :
            ANS[i] = min(B[i+1-L:i+1])
        except IndexError :
            ANS[i] = min(B[:i+1])
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

Submission status: Runtime Error

Solution code:
from collections import deque
[N,L] = [int(x) for x in input().split()]
A = {}
B = deque([])
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B.append(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if (N-count)**2 < N : break

for i in range(L):
    if i not in ANS : ANS[i] = min(B[:i+1])
for i in range(L,N):
    if i not in ANS : ANS[i] = min(B[i+1-L:i+1])
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
B = [0]*N
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B[i] = x
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count + L*0.5 > N : break
        
for i in range(L):
    if i not in ANS : ANS[i] = min(B[:i+1])
for i in range(L,N):
    if i not in ANS : ANS[i] = min(B[i+1-L:ijavascript:void(0)+1])
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

Submission status: Runtime Error

Solution code:
def SME(Part,L):
    A = {}
    B = []
    ANS = {}
    count = 0
    N = len(Part)
    for i,x in enumerate(Part):
        B.append(x)
        if x in A : A[x] += [i]
        else : A[x] = [i]
    for i in sorted(A) :
        for j in A[i] :
            for k in range(L) :
                if j + k not in ANS :
                    ANS[j+k] = i
                    count += 1
        if count > N * 0.99 : break
    for i in range(L):
        if i not in ANS : ANS[i] = min(B[:i+1])
    for i in range(L,N):
        if i not in ANS : ANS[i] = min(B[i+1-L:i+1])
    return ANS


[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
ANS = {}
M = int(N**0.3)
K = N//M
for i in range(M):
    if i == 0:
        ANS.update(SME(Whole[:K], L))
    elif i == M-1:
        ANS.update(SME(Whole[i*K-L+1:], L))
    else:
        ANS.update(SME(Whole[i*K-L+1:K-L+1+K], L))

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

Submission status: Runtime Error

Solution code:
import heapq
[N,L] = [int(x) for x in input().split()]
A = [[int(x),int(i)] for i,x in enumerate(input().split())]
heapq.heapify(A)
ANS = [10**9+1]*N
count = 0
for j in range(N):
    a = heapq.heappop(A)
    for i in range(L):
        try :
            if ANS[a[1]+i] == 10**9+1 :
                ANS[a[1]+i] = a[0]
                count += 1
        except IndexError : continue
    if count + 1000 == N : break

for i in range(L):
    if ANS[i] == 10**9+1 : ANS[i] = min(B[:i+1])
for i in range(L,N):
    if ANS[i] == 10**9+1 : ANS[i] = min(B[i+1-L:i+1])

for i in ANS[L-1:-1]:
    print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
[N,L] = [int(x) for x in input().split()]
A = [[int(x),int(i)] for i,x in enumerate(input().split())]
heapq.heapify(A)
ANS = [10**9+1]*N
count = 0
for j in range(N):
    a = heapq.heappop(A)
    for i in range(L):
        try :
            if ANS[a[1]+i] == 10**9+1 :
                ANS[a[1]+i] = a[0]
                count += 1
        except IndexError : continue
    if count + 1000 > N : break

for i in range(L):
    if ANS[i] == 10**9+1 : ANS[i] = min(B[:i+1])
for i in range(L,N):
    if ANS[i] == 10**9+1 : ANS[i] = min(B[i+1-L:i+1])

for i in ANS[L-1:-1]:
    print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(Whole,start,end,L,ANS):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] == 0 and idx <= end:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * 0.99 : break
    for i in range(L):
        if ANS[i] == 0 : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] == 0 : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ANS = [0]*N
start = 0
K = L * 2
if K > N : K = N
end = K
while (end <= N):
    ANS = SME(A, i*M, i*M+K, L, ANS)
    start = end
    end += K 
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(start,end):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] == 0:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] == 0 : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] == 0 : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
if N = 10**5 :
    parameter = 0.9999
else :
    parameter = 0.995
ANS = [0]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(start,end):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if sum(ANS[a[1]:a[1]+L]) < (a[0]-1)*(L-1) + MAX + 1
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] == MAX:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] == 0 : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] == 0 : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
parameter = 0.995
MAX = 10**9+1
ANS = [MAX]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
from functools import reduce
import operator
import heapq
def SME(start,end):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        
        if reduce(operator.mul,A[a[1]:a[1]+L])!=0 : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] == INIT:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] == INIT : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] == INIT : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
parameter = 0.995
INIT = 0
ANS = [INIT]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(Whole,start,end,L,ANS):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] == 0 and idx < end:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * 0.999 / M  : break
    for i in range(L):
        if ANS[i] == 0 : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] == 0 : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ANS = [0]*N
start = 0
K = L * int(N ** 0.3 + 2 )
if K > N : K = N
end = K
while (end <= N):
    ANS = SME(A, start, end, L, ANS)
    start = end
    end += K 
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
#??????????????????
import heapq
def SME(start,end):
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.Add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in C.difference(D):
        if i < L:
            ANS[i] = min(Whole[:i+1])
        else :
            ANS[i] = min(Whole[i+1-L:i+1])
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
C = set([i for i in range(N)])
D = {}
parameter = 0.99
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
B = [0]*N
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B[i] = x
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in range(10**9) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count > N * 0.99 - 1 : break

for i in range(L):
    if i not in ANS : ANS[i] = min(B[:i+1])
for i in range(L,N):
    if i not in ANS : ANS[i] = min(B[i+1-L:i+1])
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

Submission status: Runtime Error

Solution code:
#??????????????????
import heapq
def SME():
    start = 0
    parameter = 0.99
    ANS = [None]*N
    [end,L] = [int(x) for x in input().split()]
    Whole = [int(x) for x in input().split()]
    A = []
    C = set([i for i in range(N)])
    D = set([])
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in C.difference(D):
        if i < L:
            ANS[i] = min(Whole[:i+1])
        else :
            ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

ANS = SME()
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME():
    start = 0
    parameter = 0.99
    ANS = [None]*N
    [end,L] = [int(x) for x in input().split()]
    Whole = [int(x) for x in input().split()]
    A = []
    C = set([i for i in range(N)])
    D = set([])
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in C.difference(D):
        if i < L:
            ANS[i] = min(Whole[:i+1])
        else :
            ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

ANS = SME()
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME():
    A = []
    ANS = [None] * N
    C = set([i for i in range(N)])
    D = set([])
    E = [None] * N
    parameter = 0.9997
    count = 0
    for i,x in enumerate(Whole) :
        if 0 in E[i-L//2:i] and 0 in E[i:i+l//2+1] :
            E[i] = 0
            continue
        E[i] = 0
        heapq.heappush(A,[x,i])
    for j in range(N) :
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in C.difference(D):
        if i < L : ANS[i] = min(Whole[:i+1])
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
ANS = SME()
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(start,end):
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        if i > N*0.5 : break
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.9997
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(start,end):
    count = 0
    ANS = [heapq.heappush(A,[x,i]) for i,x in enumerate(Whole)]
    for j in range(start,end):
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.97
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(start,end):
    count = 0
    ANS = [None]*N
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS
[N,L] = [int(x) for x in input().split()]
A = [[int(x),int(i)] for i,x in enumerate(input().split())]
heapq.heapify(A)
parameter = 0.9997
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME():
    A = [[x,i] for i,x in enumerate(Whole)]
    heapq.heapify(A)
    C = set([i for i in range(N)])
    D = set([])
    parameter = 0.997
    count = 0
    ANS = [None] * N
    for j in range(N) :
        a = heapq.heappop(A)
        for i in ANS[a[1]:a[1]+L]:
            if ANS[i] : continue
            else :
                ANS[i] = a[0]
                D.add(idx)
                count += 1
        if count > N * parameter : break
    for i in C.difference(D):
        if i < L : ANS[i] = min(Whole[:i+1])
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
ANS = SME()
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])