A. Cow and Haybales

滴答滴答---题目链接 

A. Cow and Haybales

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 aiai 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≤i,j≤n) such that |i−j|=1|i−j|=1 and ai>0ai>0 and apply ai=ai−1ai=ai−1, aj=aj+1aj=aj+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 a1a1), 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!

Input

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤1001≤t≤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≤n,d≤100) — the number of haybale piles and the number of days, respectively.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1000≤ai≤100)  — the number of haybales in each pile.

Output

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.

Example

input

Copy

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

output

Copy

3
101
0

Note

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.

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,d;
        cin>>n>>d;
        int a[101];
        for(int i=1; i<=n; i++)
            cin>>a[i];
        int sum=a[1];
        for(int i=2; i<=n; i++)
        {
            if(d<=0)
                break;
            while(a[i]>0&&d!=0)
            {
                int x=i-1;
                if(d>=x)
                {
                    d-=x;
                    a[i]--;
                    sum++;
                }
                else if(d<x)
                    break;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值