GUPTA MECHANICAL

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

Friday 3 June 2022

[Solution] The Enchanted Forest Codeforces Solution | Codeforces Problem Solution 2022

D. The Enchanted Forest
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Marisa comes to pick mushrooms in the Enchanted Forest.

The Enchanted forest can be represented by n points on the X-axis numbered 1 through n. Before Marisa started, her friend, Patchouli, used magic to detect the initial number of mushroom on each point, represented by a1,a2,,an.

Marisa can start out at any point in the forest on minute 0. Each minute, the followings happen in order:

  • She moves from point x to y (|xy|1, possibly y=x).
  • She collects all mushrooms on point y.
  • A new mushroom appears on each point in the forest.

Solution Click Below:-  CLICK HERE

Note that she cannot collect mushrooms on minute 0.

Now, Marisa wants to know the maximum number of mushrooms she can pick after k minutes.

Input

Each test contains multiple test cases. The first line contains a single integer t (1t104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nk (1n21051k109) — the number of positions with mushrooms and the time Marisa has, respectively.

The second line of each test case contains n integers a1,a2,,an (1ai109) — the initial number of mushrooms on point 1,2,,n.

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

Output

For each test case, print the maximum number of mushrooms Marisa can pick after k minutes.

No comments:

Post a Comment