## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## [Solution] Rising Sand Codeforces Solution | Codeforces Problem Solution 2022

B. Rising Sand
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are $n$ piles of sand where the $i$-th pile has ${a}_{i}$ blocks of sand. The $i$-th pile pile is called too tall if $1 and ${a}_{i}>{a}_{i-1}+{a}_{i+1}$. That is, a pile is too tall if it has more sand than its two neighbours combined. (Note that piles on the ends of the array cannot be too tall.)

You are given an integer $k$. An operation consists of picking $k$ consecutive piles of sand and adding one unit of sand to them all. Formally, pick $1\le l,r\le n$ such that $r-l+1=k$. Then for all $l\le i\le r$, update ${a}_{i}←{a}_{i}+1$.

What is the maximum number of piles that can simultaneously be too tall after some (possibly zero) operations?

Input

The input consists of multiple test cases. The first line contains an integer $t$ ($1\le t\le 1000$) — the number of test cases. The description of the test cases follows.

Solution Click Below:-  👉
👇👇👇👇👇

The first line of each test case contains two integers $n$ and $k$ ($3\le n\le 2\cdot {10}^{5}$$1\le k\le n$) — the number of piles of sand and the size of the operation, respectively.

The second line of each test case contains $n$ integers ${a}_{1},{a}_{2},\dots ,{a}_{n}$ ($1\le {a}_{i}\le {10}^{9}$) — the sizes of the piles.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot {10}^{5}$.

Output

For each test case, output a single integer — the maximum number of piles that are simultaneously too tall after some (possibly zero) operations.