#K88297. Minimize Wave Disruptors

    ID: 37277 Type: Default 1000ms 256MiB

Minimize Wave Disruptors

Minimize Wave Disruptors

Given an array representing the heights of n buildings arranged in a line, a building at index i (with 1 < i < n) is considered a wave disruptor (i.e. a local peak) if its height is strictly greater than the heights of its adjacent buildings. Formally, a building is a wave disruptor if

$$h_i > h_{i-1} \quad \text{and} \quad h_i > h_{i+1}. $$

You are allowed to perform at most q operations. In one operation, you may choose any building that is currently a wave disruptor and reduce its height. The reduction amount is capped at m units per operation and is applied as follows:

$$h_i := h_i - \min\Bigl( (h_i - \max(h_{i-1},h_{i+1]) + 1),\; m \Bigr). $$

Your task is to determine the minimum possible number of wave disruptors that can remain after performing at most q operations optimally. Note that if q \ge n-2, you may assume that all potential disruptors can be removed.

Input/Output Note: The program reads from standard input and writes to standard output.

inputFormat

The first line contains an integer t representing the number of test cases. Each test case is described in two lines:

  • The first line contains three space-separated integers: n (the number of buildings), m (the maximum reduction allowed per operation), and q (the maximum number of operations allowed).
  • The second line contains n space-separated integers, where the i-th integer represents the height of the i-th building.

outputFormat

For each test case, output a single integer on a new line — the minimum possible number of wave disruptors that can remain after performing up to q operations.

## sample
3
5 3 2
1 3 2 5 4
4 1 1
3 2 3 1
3 1 3
1 5 2
1

0 0

</p>