A13167 | Cow and Haybales
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of $n$ haybale piles on the farm. The $i$ -th pile contains $a_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 $i$ and $j$ ( $1 \le i, j \le n$ ) such that $|i-j|=1$ and $a_i>0$ and apply $a_i = a_i - 1$ , $a_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 $1$ (i.e. to maximize $a_1$ ), and she only has $d$ days to do so before Farmer John returns. Help her find the maximum number of haybales that may be in pile $1$ if she acts optimally!
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 $i$ and $j$ ( $1 \le i, j \le n$ ) such that $|i-j|=1$ and $a_i>0$ and apply $a_i = a_i - 1$ , $a_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 $1$ (i.e. to maximize $a_1$ ), and she only has $d$ days to do so before Farmer John returns. Help her find the maximum number of haybales that may be in pile $1$ if she acts optimally!
输入格式
The input consists of multiple test cases. The first line contains an integer $t$ ( $1 \le t \le 100$ ) — the number of test cases. Next $2t$ lines contain a description of test cases — two lines per test case.
The first line of each test case contains integers $n$ and $d$ ( $1 \le n,d \le 100$ ) — the number of haybale piles and the number of days, respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 100$ ) — the number of haybales in each pile.
The first line of each test case contains integers $n$ and $d$ ( $1 \le n,d \le 100$ ) — the number of haybale piles and the number of days, respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 100$ ) — the number of haybales in each pile.
输出格式
For each test case, output one integer: the maximum number of haybales that may be in pile $1$ after $d$ days if Bessie acts optimally.
输入输出样例
输入 #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 $3$ haybales in pile $1$ :
- On day one, move a haybale from pile $3$ to pile $2$
- On day two, move a haybale from pile $3$ to pile $2$
- On day three, move a haybale from pile $2$ to pile $1$
- On day four, move a haybale from pile $2$ to pile $1$
- 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 $2$ to pile $1$ on the second day.
- On day one, move a haybale from pile $3$ to pile $2$
- On day two, move a haybale from pile $3$ to pile $2$
- On day three, move a haybale from pile $2$ to pile $1$
- On day four, move a haybale from pile $2$ to pile $1$
- 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 $2$ to pile $1$ on the second day.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted