CF1307A.Cow and Haybales

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of nn haybale piles on the farm. The ii-th pile contains aia_i haybales.

However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an adjacent pile. Formally, in one day she can choose any two indices ii and jj (1≤i,j≤n1 \le i, j \le n) such that ∣i−j∣=1|i-j|=1 and ai>0a_i \gt 0 and apply ai=ai−1a_i = a_i - 1, aj=aj+1a_j = a_j + 1. She may also decide to not do anything on some days because she is lazy.

Bessie wants to maximize the number of haybales in pile 11 (i.e. to maximize a1a_1), and she only has dd days to do so before Farmer John returns. Help her find the maximum number of haybales that may be in pile 11 if she acts optimally!

美国计算机奥林匹克竞赛(USACO)最近要求约翰农夫在农场上排列一排 nn 堆干草垛。其中第 ii 堆包含 aia_i 个干草垛。

然而,约翰农夫刚刚出发去度假了,把一切留给了贝茜独自处理。每天,调皮的奶牛贝茜可以选择将任意一堆中的一个干草垛移动到相邻的一堆中。形式化地说,在一天内,她可以选择任意两个下标 ii 和 jj(满足 1≤i,j≤n1 \le i, j \le n 且 ∣i−j∣=1|i-j|=1),并要求 ai>0a_i > 0,然后执行操作:ai=ai−1a_i = a_i - 1,aj=aj+1a_j = a_j + 1。由于懒惰,她也可以选择某些天不进行任何操作。

贝茜希望最大化第 11 堆中的干草垛数量(即最大化 a1a_1),而她在约翰农夫返回前仅有 dd 天时间来完成这一目标。请帮助她找出:若采取最优策略,第 11 堆中最多可能有多少个干草垛!

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. Next 2t2t lines contain a description of test cases — two lines per test case.

The first line of each test case contains integers nn and dd (1≤n,d≤1001 \le n,d \le 100) — the number of haybale piles and the number of days, respectively.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1000 \le a_i \le 100) — the number of haybales in each pile.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。接下来的 2t2t 行描述了各测试用例,每个测试用例占两行。

每个测试用例的第一行包含两个整数 nn 和 dd(1≤n,d≤1001 \le n,d \le 100),分别表示干草堆的数量和天数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1000 \le a_i \le 100),表示每堆干草的数量。

输出格式

For each test case, output one integer: the maximum number of haybales that may be in pile 11 after dd days if Bessie acts optimally.

对于每个测试用例,输出一个整数:若贝茜采取最优策略,则经过 dd 天后,堆 11 中可能含有的干草捆最大数量。

输入输出样例

  • 输入#1

    3
    4 5
    1 0 3 2
    2 2
    100 1
    1 8
    0

    输出#1

    3
    101
    0

说明/提示

In the first test case of the sample, this is one possible way Bessie can end up with 33 haybales in pile 11:

  • On day one, move a haybale from pile 33 to pile 22
  • On day two, move a haybale from pile 33 to pile 22
  • On day three, move a haybale from pile 22 to pile 11
  • On day four, move a haybale from pile 22 to pile 11
  • On day five, do nothing

In the second test case of the sample, Bessie can do nothing on the first day and move a haybale from pile 22 to pile 11 on the second day.

在样例的第一个测试用例中,以下是一种贝茜最终使第 11 堆干草堆拥有 33 个干草捆的可能方式:

  • 第一天:将一个干草捆从第 33 堆移动到第 22 堆
  • 第二天:将一个干草捆从第 33 堆移动到第 22 堆
  • 第三天:将一个干草捆从第 22 堆移动到第 11 堆
  • 第四天:将一个干草捆从第 22 堆移动到第 11 堆
  • 第五天:不进行任何操作

在样例的第二个测试用例中,贝茜可以在第一天不进行任何操作,并在第二天将一个干草捆从第 22 堆移动到第 11 堆。

输入解题思路,AI测评打分。不知道怎么写?

首页