Cow and Haybales

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 a_iai​ 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 \le i, j \le n1≤i,j≤n) such that |i-j|=1∣i−j∣=1 and a_i>0ai​>0 and apply a_i = a_i - 1ai​=ai​−1, a_j = a_j + 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 a_1a1​), 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 \le t \le 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 \le n,d \le 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 a_1, a_2, \ldots, a_na1​,a2​,…,an​ (0 \le a_i \le 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.

Sample 1

InputcopyOutputcopy
3
4 5
1 0 3 2
2 2
100 1
1 8
0
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.

题意:

有n个干草堆,可以在相邻的草堆之间搬草,每次可以搬一个草,给你d次搬运的机会以及每个草堆中草的数量,问第一个草堆最多可以有多少草。

思路:

直接模拟,先从第二个草堆搬到第一个草堆,每个草花费1次搬运;再从第三个草堆搬到第一个草堆,每个草花费2次搬运...直到搬运次数不足。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
void slove()
{
    int t;
    cin>>t;
    while(t--)
    {
        int ans=0;
        int n,d;
        cin>>n>>d;
        for(int i=0;i<n;i++)
        {
            int k;
            cin>>k;
            if(k*i<=d)
            {
                ans+=k;
                d-=k*i;
            }
            else
            {
                ans+=d/i;
                d=0;
            }
        }
        cout<<ans<<endl;
    }
}
int main()
{
    slove();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Cow是指Android系统中的一种特定的错误。它是由于内存溢出或者内存泄漏而导致的系统崩溃或应用程序闪退的问题。在Android系统中,每个应用程序都会分配一定的内存空间来存储数据和临时变量。当应用程序运行时,它会不断地创建和销毁对象,不断地使用内存空间。如果应用程序没有正确管理内存,那么就有可能出现内存溢出的情况,即消耗的内存超过了分配的内存空间。当内存溢出发生时,Android系统就会发出一个“cow”错误,即OOM(Out Of Memory)错误。 Android Cow错误可以引发以下一些问题:应用程序可能会变得非常缓慢,用户界面回应变得迟钝;应用程序可能会频繁崩溃或闪退,导致用户无法正常使用;应用程序可能会占用过多的系统资源,导致其他应用程序无法正常运行;在极端情况下,Android系统甚至可能因为内存溢出而完全崩溃。 为了避免Android Cow错误,开发者应该注意对内存的合理使用和垃圾回收机制的优化。例如,避免创建太多的临时对象;及时释放不再使用的对象;使用适当的数据结构来优化内存占用等。同时,应用程序也应该处理好内存溢出时的异常情况,例如通过捕获OOM错误并进行相应的处理代码。 总而言之,Android Cow错误是由于内存溢出或内存泄漏导致的系统崩溃问题,开发者需要采取相应的措施来避免这种错误的发生。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值