Time limit: 0.5sMemory limit: 1024MBInput: balama.inOutput: balama.out
At the woodworking exam, the future engineers were given a door with N hinges, each with a resistance R1,…,RN.
The first test of the exam consists of determining the total resistance of the door, which is a sequence T1,…,TK formed of K numbers, computed as follows.
First, we define the matrix Aij with N−K+1 rows and K columns, such that the i-th row of A is the subsequence Ri,…,Ri+K−1 of the sequence R. For example, if N=9, R=[2,5,4,3,2,1,8,7,3] and K=3, then:
A=254321854321874321873
Then, we define the matrix Bij, also with N−K+1 rows and K columns, such that the i-th row of B contains exactly the elements of row i of matrix A, but sorted in increasing order. For example, for the previous values of N and R we have that:
B=232111344322775543888
Finally, we define Tj as the maximum of column j of B, that is, Tj=maxiBij. In the example above, the column maximums are 3, 7, 8, and are boxed.
Requirement
Given N, K, and R1,…,RN, compute T1,…,TK.
Input Data
The first line of the file balama.in will contain the numbers N and K, with the meaning given in the statement. On the next line will be the resistances of the N hinges R1,…,RN, separated by spaces.
Output Data
The output file balama.out will contain K numbers separated by spaces, the i-th number representing Ti.
Constraints and Notes
1≤N≤200000
1≤K≤N
0≤Ri≤109 for 1≤i≤N
#
Score
Constraints
1
5
1≤N≤1000
2
6
1≤N≤10000
3
9
0≤Ri≤1 for 1≤i≤N
4
38
1≤N≤75000
5
42
No additional restrictions
Note: Subtask 5 contains five groups of tests, worth 7, 8, 8, 9, and 10 points respectively.
Example
balama.in
9 3
2 5 4 3 2 1 8 7 3
balama.out
3 7 8
Explanation
Matrix A has the values 254321854321874321873
Matrix B has the values 232111344322775543888