Codeforces Round 796 (Div. 1)
A
The Enchanted Forest
Codeforces
1600
原题
←B →
翻译中…

The enchanted forest got its name from the magical mushrooms growing here. They may cause illusions and generally should not be approached.—Perfect Memento in Strict Sense

翻译中…

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 $a_1,a_2,\ldots,a_n$.

翻译中…

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$ ($|x-y|\le 1$, possibly $y=x$).
  • She collects all mushrooms on point $y$.
  • A new mushroom appears on each point in the forest.
翻译中…

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$ ($1 \leq t \leq 10^4$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$, $k$ ($1 \le n \le 2 \cdot 10 ^ 5$, $1\le k \le 10^9$) — the number of positions with mushrooms and the time Marisa has, respectively.

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le 10^9$) — the initial number of mushrooms on point $1,2,\ldots,n$.

翻译中…

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

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

Test case 1:

翻译中…

Marisa can start at $x=2$. In the first minute, she moves to $x=1$ and collect $5$ mushrooms. The number of mushrooms will be $[1,7,2,3,4]$. In the second minute, she moves to $x=2$ and collects $7$ mushrooms. The numbers of mushrooms will be $[2,1,3,4,5]$. After $2$ minutes, Marisa collects $12$ mushrooms.

翻译中…

It can be shown that it is impossible to collect more than $12$ mushrooms.

翻译中…

Test case 2:

翻译中…

This is one of her possible moving path:

翻译中…

$2 \rightarrow 3 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 5$

翻译中…

It can be shown that it is impossible to collect more than $37$ mushrooms.

翻译中…

样例

Input #1
4
5 2
5 6 1 2 3
5 7
5 6 1 2 3
1 2
999999
5 70000
1000000000 1000000000 1000000000 1000000000 1000000000
Output #1
12
37
1000000
5000349985
InputCopy OutputCopy
题目信息
题号
1687A
时间限制
2 s
内存限制
256 MB
标签
暴力
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。