CF1687A.The Enchanted Forest

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn points on the XX -axis numbered 11 through nn . Before Marisa started, her friend, Patchouli, used magic to detect the initial number of mushroom on each point, represented by a1,a2,,ana_1,a_2,\ldots,a_n .

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

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

Note that she cannot collect mushrooms on minute 00 .

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

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t1041 \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 nn , kk ( 1n21051 \le n \le 2 \cdot 10 ^ 5 , 1k1091\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 nn integers a1,a2,,ana_1,a_2,\ldots,a_n ( 1ai1091 \le a_i \le 10^9 ) — the initial number of mushrooms on point 1,2,,n1,2,\ldots,n .

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

输出格式

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

输入输出样例

  • 输入#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

    输出#1

    12
    37
    1000000
    5000349985

说明/提示

Test case 1:

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

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

Test case 2:

This is one of her possible moving path:

232123452 \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 3737 mushrooms.

首页