#P9889. [ICPC2018 Qingdao R] Plants vs. Zombies

    ID: 9252 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>贪心2018二分O2优化ICPC青岛

[ICPC2018 Qingdao R] Plants vs. Zombies

题目描述

BaoBao and DreamGrid are playing the game Plants vs. Zombies\textit{Plants vs. Zombies}. In the game, DreamGrid grows plants to defend his garden against BaoBao's zombies.

$\textit{Plants vs. Zombies(?)} \\ \textit{(Image from pixiv. ID: 21790160; Artist: socha)}$

There are nn plants in DreamGrid's garden arranged in a line. From west to east, the plants are numbered from 1 to nn and the ii-th plant lies ii meters to the east of DreamGrid's house. The ii-th plant has a defense value of did_i and a growth speed of aia_i. Initially, di=0d_i = 0 for all 1in1 \le i \le n.

DreamGrid uses a robot to water the plants. The robot is in his house initially. In one step of watering, DreamGrid will choose a direction (east or west) and the robot moves exactly 1 meter along the direction. After moving, if the ii-th plant is at the robot's position, the robot will water the plant and aia_i will be added to did_i. Because the water in the robot is limited, at most mm steps can be done.

The defense value of the garden is defined as min{di1in}\min\{d_i | 1 \le i \le n\}. DreamGrid needs your help to maximize the garden's defense value and win the game.

  • Each time the robot MUST move before watering a plant;
  • It's OK for the robot to move more than nn meters to the east away from the house, or move back into the house, or even move to the west of the house.

输入格式

There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains two integers nn and mm (2n1052 \le n \le 10^5, 0m10120 \le m \le 10^{12}), indicating the number of plants and the maximum number of steps the robot can take.

The second line contains nn integers a1,a2,...,ana_1, a_2, ... , a_n (1ai1051 \le a_i \le 10^5), where aia_i indicates the growth speed of the ii-th plant.

It's guaranteed that the sum of nn in all test cases will not exceed 10610^6.

输出格式

For each test case output one line containing one integer, indicating the maximum defense value of the garden DreamGrid can get.

题目大意

给定 nn 个植物和 mm 的步数限制,每个植物在位置 1n1\dots n 上。你初始时在位置 00,每次可以移动到相邻的位置上。

每次设你走完一步后到达的位置是 ii,则会使得这个位置的植物的高度增加 aia_i。设 did_i 为走完 mm 步后位置 ii 的植物高度,求出一个最优的走法使得 min1indi\min\limits_{1 \le i \le n} d_i 最大。

2n1052\leq n\leq 10 ^ 50m10120\leq m\leq 10 ^ {12}1ai1051\leq a_i\leq 10 ^ 5n106\sum n\leq 10 ^ 6

2
4 8
3 2 6 6
3 9
10 10 1
6
4

提示

In the explanation below, E indicates that the robot moves exactly 1 meter to the east from his current position, and W indicates that the robot moves exactly 1 meter to the west from his current position.

For the first test case, a candidate direction sequence is {E,E,W,E,E,W,E,E}\{E, E, W, E, E, W, E, E\}, so that we have d={6,6,12,6}d = \{6,6,12,6\} after the watering.

For the second test case, a candidate direction sequence is {E,E,E,E,W,E,W,E,W}\{E, E, E, E, W, E, W, E, W\}, so that we have d={10,10,4}d = \{10, 10, 4\} after the watering.