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

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

hide comments
2013-05-13 03:55:53 natsu
used O(nk) with slight modifications
got AC finally after 8 wa
2013-05-10 09:54:10 Code Geass
my code is giving wrong answer after 5th test case even it is working correctly on all test cases.....
2013-04-04 16:39:32 Atul Kashyap
getting wa after 5th test case....even though not printing space after last o/p...
2013-03-29 06:04:58 Indrajit Sarkar
Be careful with spaces.
Dont give space after the last output
2013-03-21 20:53:48 Man Mohan Mishra
awesome problem !!
application of recently learnt data structure for me :)
2013-02-23 16:56:16 Sundaravel V
am getting tle :( after running(5)
2013-02-23 16:55:08 Sundaravel V
got stuck in in tle after 5th judging!!:( any one help me

Last edit: 2013-03-15 19:20:05
2013-02-21 18:16:32 Rajnikanth
finally AC.....after 4 WA and 4 TLE
2013-02-19 19:17:01 Inspiron
AC
2012-12-07 04:10:04 tarun sharma
getting tle in 5th test case....?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.