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
2015-07-14 12:44:20 jas.py
Few test cases :
7
1 2 8 4 5 2 3
3
8 8 8 5 5

7
1 2 8 4 5 2 3
4
8 8 8 5
(Copied from a comment on page 11(had go really far)...were useful to me)
2015-06-25 17:07:46 Liquid_Science
Segment tree & brute force with optimisations both gives tle in java -_-

finally ac with dp:) O(n)

Last edit: 2015-06-26 11:10:38
2015-06-25 11:26:47 Aman Parashar
This is bad !! Brute force should not work but works !! O(nk) - no way !!
For a non increasing array it should give TLE !!

Last edit: 2015-06-25 11:32:24
2015-06-23 21:07:56 Deepak Singh Tomar
segment tree works fine
2015-06-20 09:53:19 SangKuan
ac in first by dp.must has other better way
2015-06-15 21:58:14 Ooo....
my 150th on spoj =D
2015-06-14 22:23:43 burninggoku
recursion rejected....set rejected...brute force accepted.... my 23.56th !!!
2015-06-13 13:41:45 sujit yadav
submit with c++14 compiler coz c++ 4.3.2 gave me TLE for the same solution . simple brute force ..dont forget spaces between integers .

Last edit: 2015-06-13 13:45:02
2015-06-03 13:55:02 [Mayank Pratap]
Brute force with optimisation .... AC ... :)
2015-05-29 14:49:07 Jerry Goyal
what's the fuss about?..simple bruteforce.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.