Sim-4-15 | Balama

This was the problem page during the contest. Access the current page here.
Time limit: 0.5s Memory limit: 1024MB Input: balama.in Output: balama.out

At the woodworking exam, the future engineers were given a door with NN hinges, each with a resistance R1,,RNR_1, \dots, R_N.

The first test of the exam consists of determining the total resistance of the door, which is a sequence T1,,TKT_1, \dots, T_K formed of KK numbers, computed as follows.

First, we define the matrix AijA_{ij} with NK+1N - K + 1 rows and KK columns, such that the ii-th row of AA is the subsequence Ri,,Ri+K1R_i, \dots, R_{i+K-1} of the sequence RR. For example, if N=9N = 9, R=[2,5,4,3,2,1,8,7,3]R = [2, 5, 4, 3, 2, 1, 8, 7, 3] and K=3K = 3, then:

A=(254543432321218187873)A = \begin{pmatrix} 2 & 5 & 4\\ 5 & 4 & 3\\ 4 & 3 & 2\\ 3 & 2 & 1\\ 2 & 1 & 8\\ 1 & 8 & 7\\ 8 & 7 & 3 \end{pmatrix}

Then, we define the matrix BijB_{ij}, also with NK+1N - K + 1 rows and KK columns, such that the ii-th row of BB contains exactly the elements of row ii of matrix AA, but sorted in increasing order. For example, for the previous values of NN and RR we have that:

B=(245345234123128178378)B = \begin{pmatrix} 2 & 4 & 5\\ \fbox{3} & 4 & 5\\ 2 & 3 & 4\\ 1 & 2 & 3\\ 1 & 2 & \fbox{8}\\ 1 & \fbox{7} & \fbox{8}\\ \fbox{3} & \fbox{7} & \fbox{8} \end{pmatrix}

Finally, we define TjT_j as the maximum of column jj of BB, that is, Tj=maxiBijT_j = \max_i B_{ij}. In the example above, the column maximums are 33, 77, 88, and are boxed.

Requirement

Given NN, KK, and R1,,RNR_1, \dots, R_N, compute T1,,TKT_1, \dots, T_K.

Input Data

The first line of the file balama.in will contain the numbers NN and KK, with the meaning given in the statement. On the next line will be the resistances of the NN hinges R1,,RNR_1, \dots, R_N, separated by spaces.

Output Data

The output file balama.out will contain KK numbers separated by spaces, the ii-th number representing TiT_i.

Constraints and Notes

  • 1N200 0001 \leq N \leq 200 \ 000
  • 1KN1 \leq K \leq N
  • 0Ri1090 \leq R_i \leq 10^9 for 1iN1 \leq i \leq N
# Score Constraints
1 5 1N1 0001 \leq N \leq 1 \ 000
2 6 1N10 0001 \leq N \leq 10 \ 000
3 9 0Ri10 \leq R_i \leq 1 for 1iN1 \leq i \leq N
4 38 1N75 0001 \leq N \leq 75 \ 000
5 42 No additional restrictions

Note: Subtask 5 contains five groups of tests, worth 77, 88, 88, 99, and 1010 points respectively.

Example

balama.in

9 3
2 5 4 3 2 1 8 7 3

balama.out

3 7 8

Explanation

Matrix AA has the values
(254543432321218187873)\begin{pmatrix} 2 & 5 & 4\\ 5 & 4 & 3\\ 4 & 3 & 2\\ 3 & 2 & 1\\ 2 & 1 & 8\\ 1 & 8 & 7\\ 8 & 7 & 3 \end{pmatrix}

Matrix BB has the values
(245345234123128178378)\begin{pmatrix} 2 & 4 & 5\\ 3 & 4 & 5\\ 2 & 3 & 4\\ 1 & 2 & 3\\ 1 & 2 & 8\\ 1 & 7 & 8\\ 3 & 7 & 8 \end{pmatrix}

The column maximums are 33, 77, 88.

Log in or sign up to be able to send submissions!