ARRAYSUB - subarrays


Given an array and an integer k, find the maximum for each and every contiguous subarray of size k.

Input

the number n denoting number of elements in the array then after a new line we have the numbers of the array and then k in a new line

n < 10^6
k < 10^5
1 <= k <= n

and each element of the array is between 0 and 10^6

(Edited: In fact, n <= 10^5)

Output

print the output array

Example

Input:
9
1 2 3 1 4 5 2 3 6
3

Output:
3 3 4 5 5 5 6

hide comments
***: 2013-07-19 17:50:51

finally!!! got AC!!!

Last edit: 2013-07-19 17:52:28
ankit kumar sinha: 2013-07-10 08:49:47

5th test case????
please

pika_pika: 2013-06-29 16:33:29

Python 2.x or 3.x gives a stupid error of indentation which is syntactically correct yet the spoj engie goes crazy

Himanshu: 2013-06-25 06:54:24

0.19 AC in one go!!
yippy

Aditya Pande: 2013-06-23 21:05:50

0.10 sec in optimized O(nk)
surprised myself

Last edit: 2013-06-24 06:08:01
Shashank_Jain: 2013-06-23 08:40:53

Simple DP in O(n) and AC ! baam !

Vipul Pandey: 2013-06-14 13:40:42

no use of any data structure.


Added by:priyamehtanit
Date:2012-02-09
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:own