Yasser's Medians

3.5

2 votes
Data Structures, Binary indexed tree, Datastructures, Advanced Data Structures, Fenwick (Binary Indexed) Trees
Problem

Given numbers and an integer find :

Formally: we can define  as the maximum median of each subarray of length .

Note that: the median of numbers indexed from  is  smallest of them, rounding down for even .

 

Input format

  • The first line contains two integers and denoting the number of elements and size of the subarray.
  • The second line contains  space-separated integers.

Output format

Print the answer as described above.

Constraints

Sample Input
4 2
1 2 3 4
Sample Output
64
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In the example, we can notice that we have 3 subarrays of size 2 

{1,2},{2,3},{3,4} here the median of every subarray is the mean of the 2 middle values (rounded down) since we have an even size subarray.

all medians will be(1,2,3) and the  is 3 and finally  will be .

Editor Image

?