#K64112. Max Covered Building Height

    ID: 31904 Type: Default 1000ms 256MiB

Max Covered Building Height

Max Covered Building Height

You are given an array of positive integers representing the heights of buildings. You also have a gadget that can cover exactly k consecutive buildings. Your task is to determine the maximum height of the tallest building that can be covered by the gadget when applied to any segment of k consecutive buildings.

Formally, given an array \(heights\) of length \(n\) and a positive integer \(k\) (where \(1 \le k \le n\)), find the maximum value of \(\max(heights[i], heights[i+1], \dots, heights[i+k-1])\) over all valid \(i\) (i.e., \(0 \le i \le n-k\)).

Note: The gadget covers exactly k consecutive buildings, and you need to choose the segment that results in the maximum possible building height covered.

inputFormat

The first line contains two integers \(n\) and \(k\) separated by a space, where \(n\) is the number of buildings and \(k\) is the number of consecutive buildings that can be covered by the gadget.

The second line contains \(n\) space-separated positive integers representing the heights of the buildings.

outputFormat

Output a single integer, which is the maximum height of the tallest building in any segment of k consecutive buildings.

## sample
5 3
1 3 2 4 5
5

</p>