题目传送门

题目大意:有n个植物排成一排,标号为1-n,每株植物有自己的生长速度ai,每对植物浇一次水,该株植物就长高ai,现在机器人从第0个格子出发,每次走一步,不能停留,每一步浇一次水,总共可以走m步,问最矮的植物最高是多少。

思路:

  一般此类最小值最大问题都是二分,此题显然也是可以二分植物的高度的。

  确定某一个高度后,也确定了每个植物需要浇几次水,而对于一株植物来说,应当尽可能的在这株植物和后面那个格子来回走,是这株植物迅速超过最低高度(这样的走法是最优的,因为可以想象,如果往后走很多步再走回来,中间浪费的可能性比较大),于是就是对n个植物模拟浇水,考虑一些细节就可以了(二分跳出条件,long long等等)

//#pragma comment(linker,"/STACK:102400000,102400000")
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<stdlib.h>
//#include<unordered_map>
#define lson l,mid,rt<<1
#define rson mid+1,r,(rt<<1)|1
#define CLR(a,b) memset(a,b,sizeof(a))
#define mkp(a,b) make_pair(a,b)
typedef long long ll;
using namespace std;
inline ll read(){
ll x=,f=;
char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;}
const int maxn=;
int n;
ll a[maxn],c[maxn],m;
inline bool judge(ll high){
CLR(c,);
ll temp=m;
if(m==)return false;
c[]=a[],m--;
int i=;
for(;i<=n;i++)
{
if(m<=)break;
if(c[i]>=high)
{
if(m>)
{
c[i+]=a[i+];
m--;
continue;
}else{
break;
}
}
ll tmp=(ll)ceil((high-c[i])*1.0/a[i]);
if(m>*tmp){
m-=*tmp+;
c[i]+=a[i]*tmp;
c[i+]+=a[i+]*(tmp+);
continue;
}else if(m==*tmp){
c[i]+=a[i]*tmp;
c[i+]+=a[i+]*tmp;
break;
}else{
break;
}
}
m=temp;
for(i=;i<=n;i++)
{
if(c[i]<high)return false;
}
return true;
}
int main(){
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
ll l=,r=,mid,ans;
for(int i=;i<=n;i++){
a[i]=read();
r=max(r,a[i]*m);
}
if(m==){
printf("0\n");
continue;
} while(l<=r)
{
mid=(l+r)>>;
// printf("mid %d\n",mid);
if(judge(mid))
{
ans=mid;
l=mid+;
}else{
r=mid-;
}
}
printf("%lld\n",ans);
}
}

Plants vs. Zombies


Time Limit: 2 Seconds      Memory Limit: 65536 KB

BaoBao and DreamGrid are playing the game Plants vs. Zombies. In the game, DreamGrid grows plants to defend his garden against BaoBao's zombies.


Plants vs. Zombies(?)
(Image from pixiv. ID: 21790160; Artist: socha)

There are  plants in DreamGrid's garden arranged in a line. From west to east, the plants are numbered from 1 to  and the -th plant lies  meters to the east of DreamGrid's house. The -th plant has a defense value of  and a growth speed of . Initially,  for all .

DreamGrid uses a robot to water the plants. The robot is in his house initially. In one step of watering, DreamGrid will choose a direction (east or west) and the robot moves exactly 1 meter along the direction. After moving, if the -th plant is at the robot's position, the robot will water the plant and  will be added to . Because the water in the robot is limited, at most  steps can be done.

The defense value of the garden is defined as . DreamGrid needs your help to maximize the garden's defense value and win the game.

Please note that:

  • Each time the robot MUST move before watering a plant;
  • It's OK for the robot to move more than  meters to the east away from the house, or move back into the house, or even move to the west of the house.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers  and  (, ), indicating the number of plants and the maximum number of steps the robot can take.

The second line contains  integers  (), where  indicates the growth speed of the -th plant.

It's guaranteed that the sum of  in all test cases will not exceed .

Output

For each test case output one line containing one integer, indicating the maximum defense value of the garden DreamGrid can get.

Sample Input

2
4 8
3 2 6 6
3 9
10 10 1

Sample Output

6
4

Hint

In the explanation below, 'E' indicates that the robot moves exactly 1 meter to the east from his current position, and 'W' indicates that the robot moves exactly 1 meter to the west from his current position.

For the first test case, a candidate direction sequence is {E, E, W, E, E, W, E, E}, so that we have  after the watering.

For the second test case, a candidate direction sequence is {E, E, E, E, W, E, W, E, W}, so that we have  after the watering.

最新文章

  1. jsonP跨域调用
  2. 手机web站点和手机app 技术选型的困惑于思考
  3. 【LeetCode】273. Integer to English Words
  4. [0x00 用Python讲解数据结构与算法] 概览
  5. socket(TCP)发送文件
  6. Scala-逻辑判断
  7. journaling保证意外故障下的数据完整性
  8. 201521123063 《Java程序设计》 第8周学习总结
  9. JAVA发红包案例
  10. Educational Codeforces Round 53 (Rated for Div. 2) A Diverse Substring
  11. flask_script 创建自定义命令行
  12. 如何将同一云服务下的虚拟机从经典部署模型迁移到 Azure Resource Manager
  13. Linux netstat命令具体解释
  14. hdu1598
  15. WPF不同线程之间的控件的访问
  16. linq 左连接实现两个集合的合并
  17. 简单说一说对JavaScript原型链的理解
  18. Codeforces Round #262 (Div. 2) A. Vasya and Socks【暴力/模拟/袜子在可以在合法情况下增加后用几天】
  19. spring事务的开启方式(编程式和声明式)
  20. 06使用NanoPiM1Plus在Android4.4.2下接U盘

热门文章

  1. SpringBoot23 分模块开发
  2. 性能优化之_android布局优化
  3. k阶原点距和k阶中心距各是说明什么数字特征
  4. Django框架 之 admin管理工具(组件使用)
  5. Django框架 之 中间件
  6. Part4_lesson2---ARM处理器这个硬件启动流程分析
  7. BZOJ 2301 Problem b(莫比乌斯反演+分块优化)
  8. Java Serializable(序列化)的理解和总结
  9. 「CF932E」 Team Work
  10. 类与类之间的两种关系------新标准c++程序设计