GUPTA MECHANICAL

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

Tuesday 28 June 2022

[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 ai blocks of sand. The i-th pile pile is called too tall if 1<i<n and ai>ai1+ai+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 1l,rn such that rl+1=k. Then for all lir, update aiai+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 (1t1000) — the number of test cases. The description of the test cases follows.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

The first line of each test case contains two integers n and k (3n21051kn) — the number of piles of sand and the size of the operation, respectively.

The second line of each test case contains n integers a1,a2,,an (1ai109) — the sizes of the piles.








It is guaranteed that the sum of n over all test cases does not exceed 2105.

Output

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

No comments:

Post a Comment