首页 > 其他分享 >CodeForces Round #621 ABC (1307A+1307B+1307C) 题解

CodeForces Round #621 ABC (1307A+1307B+1307C) 题解

时间:2024-09-08 20:38:33浏览次数:1  
标签:621 ABC int 题解 number le pile test hidden

A. Cow and Haybales

题面

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!

输入

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,\dots,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.

样例

输入

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

输出

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 \(3\) 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.

解题思路

贪心算法:先把第二堆的移到第一堆,再把第三堆的移到第一堆,……
题目中的样例解释有点误导(

标签:621,ABC,int,题解,number,le,pile,test,hidden
From: https://www.cnblogs.com/stanleys/p/18403384/cf1307

相关文章

  • 2024CCPC网络赛题解
    前言开局掉线30min比较搞心态,不过比赛延迟了1个小时,但是后面也一直没过题,如果时间再少点可能排名还更好看。最后是8题前面,这里简单讲一下我有写的题,队友写的题就放一下队友的赛时代码,大家自己看看吧。B队友写的,签到,但是数据范围\(n\)给\(10^3\)给队友整不自信了,因为答案的......
  • ABC370 Review
    ABC370ReviewA模拟题,过B模拟题,过C很明显的贪心思路是把需要更改的字母分为两类:改大和改小。首先我们要明确的是要让输出的串尽量拥有小的字典序,且字典序比较的第一关键字是位置,第二是长度所以对于改小的部分,改的位置越靠前我们就放在越前面操作;对于改大的部分,改的位置......
  • AT_dwacon6th_prelims_c Cookie Distribution 题解
    组合意义保平安。思路发现\(\prod\)的贡献不好统计。我们可以考虑\(\prod\)的组合意义。容易发现:\[\prodc_i=\prod\sum_{j=1}^{c_i}1\]那么依照分配律,我们发现这个东西的组合意义是每个人从获得的饼干中选一个出来的方案。这样就会变好统计很多。设\(dp_{i,j}\)为......
  • CF1534F2 Falling Sand (Hard Version) 题解
    题目链接点击打开链接题目解法做法1一个沙子消失,会带走所有它所在列下面的沙子我们记每列从下往上第\(a_i\)个沙子为关键点,第\(i\)列至少消失\(a_i\)个沙子等价于所有关键点都消失一个显然的事情是:记一列最上面的沙子为起始点,则我们只会干扰起始点第一感觉是找到一......
  • トヨタ自動車プログラミングコンテスト2024#9(ABC370)
    A.RaiseBothHands\(\texttt{Diff}11\)#include<bits/stdc++.h>usingnamespacestd;#defineendl'\n'#definevoidinlinevoid//#defineONLINE_JUDGE#ifndefONLINE_JUDGE#definetest(i)cout<<"test:"<<i<<......
  • LOJ4218 「IOI2024」尼罗河船运 题解
    题目描述有\(n\)件手工艺品,第\(i\)件重量为\(w_i\),有参数\(a_i\)和\(b_i\)。每艘船最多可以运输两件手工艺品:如果只运输第\(i\)件,重量没有要求,代价为\(a_i\)。如果同时运输第\(i\)和第\(j\)件,要求\(|w_i-w_j|\leD\),代价\(b_i+b_j\)。\(q\)次询问,给......
  • Leetcode第 414 场周赛题解
    Leetcode第414场周赛题解Q1.将日期转换为二进制表示给你一个字符串date,它的格式为yyyy-mm-dd,表示一个公历日期。date可以重写为二进制表示,只需要将年、月、日分别转换为对应的二进制表示(不带前导零)并遵循year-month-day的格式。返回date的二进制表示。解法:STL一......
  • 题解:P11020 「LAOI-6」Radiation
    我们发现一种最优策略,把石头按照斜线摆,即(1,1),......
  • P1419 寻找段落 题解
    其他学习笔记这题真是凝聚了很多精华,那么我们就介绍这题的四兄弟:大哥平均数这道题是其他兄弟的基础。二哥BestCow这位更是重量级,因为没特长只能强大哥的外貌,会大哥即识二哥。三哥PROSJEK这位哥看似有点创新却仍没逃过一家子的基因,只是变为了小数运算。四哥寻......
  • 【题解】CPS-S模拟2
    目录PreT1.不相邻集合题目描述部分分40pts10pts正解思路代码T2.线段树题目描述部分分20pts正解思路代码T3.部分分40pts正解思路代码T4.部分分10pts正解思路代码AndPre赛时没有第一时间找到签到题,遂四处游走,后来决定先打T1,约1h时切了,然后1h打后3题暴力,后面推了推T4一个特殊性质,......