C - Present

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions.

There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water wcontiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?

Input

The first line contains space-separated integers nm and w(1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an(1 ≤ ai ≤ 109).

Output

Print a single integer — the maximum final height of the smallest flower.

Sample Input

Input
6 2 3
2 2 2 2 1 1
Output
2
Input
2 5 1
5 8
Output
9

先说题意:共有n盆花列为一排,输入n盆花的现高度,可浇水m天,每天只能浇一次,每次浇水只能浇相邻的w株,每浇水一次花长高1,求m天后最矮的花最高为多少。

可用二分答案的方法,将可能的高度二分,再比较在m天内能不能达到二分的数值,若能则继续向上二分答案,若不能则向下二分答案,直到找出最合适的值。

附AC代码:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std; const int MAX=;
long long a[MAX],b[MAX],v[MAX]; int main(){
int n,m,w;
while(~scanf("%d %d %d",&n,&m,&w)){
long long low=1e9,top=-;
for(int i=;i<=n;i++){
scanf("%I64d",&a[i]);
if(a[i]<low)
low=a[i];
if(a[i]>top)
top=a[i];
}
top+=m;
long long mid,ans=-;
while(top>=low){
mid=(top+low)/;//中点
for(int i=;i<=n;i++)
b[i]=max(mid-a[i],(long long));//到达中点所需要的天数
memset(v,,sizeof(v));//v数组用来实现连续浇水w
long long day=m;//day表示天数
long long c=;//已浇水天数
for(int i=;i<=n;i++){
c+=v[i];//w个后c归零
b[i]-=c;//已浇c天
if(b[i]>){
day-=b[i];
if(day<)//天数不够
break;
else
c+=b[i];
v[i+w]-=b[i];//当i循环到w个后时,这些花之前并没有被浇水,所以减去,由循环开头式子得c=0
b[i]=;//已交够水了所以为0
}
}
if(day<){//当天数不够时向下二分答案
top=mid-;
}
else{//继续向上二分
ans=mid;
low=mid+;
}
}
printf("%I64d\n",ans);
}
return ;
}

C - Present的更多相关文章

  1. 跳转时候提示Attempt to present on while a presentation is in progress

    出现这种情况,例如:我在获取相册图片后,直接present到另一个页面,但是上一个页面可能还未dismiss,所以,要在获取相册图片的dismiss方法的complete的block里面写获取图片及跳 ...

  2. find your present (感叹一下位运算的神奇)

    find your present (2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. HTTP Status 400 - Required String parameter 'userName' is not present 错误

    HTTP Status 400 - Required String parameter 'userName' is not present 错误 先mark  有时间详细写 参考链接: https:/ ...

  4. Linux 克隆虚拟机引起的“Device eth0 does not seem to be present, delaying initialization”

    虚拟机Vmware上克隆了一个Red Hat Enterprise Linx启动时发现找不到网卡,如下所示,如果你在命令窗口启动网络服务就会遇到"Device eth0 does not s ...

  5. required string parameter XXX is not present

    @RequestParam jQuery调用方式: deleteFile: function(filePath) { return ajax({ method: 'POST', url: '/cm/s ...

  6. 启动网卡报:Device eth0 does not seem to be present”解决办法

    Device eth0 does not seem to be present”解决办法 : 用ifconfig查看发现缺少eth0,只有lo:用ifconfig -a查看发现多出了eth1的信息. ...

  7. jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque

    问题: XMLHttpRequest cannot load http://v.xxx.com. No 'Access-Control-Allow-Origin' header is present ...

  8. js跨域访问,No 'Access-Control-Allow-Origin' header is present on the requested resource

    js跨域访问提示错误:XMLHttpRequest cannot load http://...... No 'Access-Control-Allow-Origin' header is prese ...

  9. sudo: no tty present and no askpass program specified(转)

    sudo: no tty present and no askpass program specified 2012-11-30 09:30 5040人阅读 评论(1) 收藏 举报 修改sudo配置文 ...

  10. 虚拟机解决Device eth0 does not seem to be present 问题。

    Device eth0 does not seem to be present... 出现这个问题基本上是因为虚拟机是克隆的导致机器的mac网卡不一致,所以系统识别网卡失败:

随机推荐

  1. Java、C++、Python、Ruby、PHP、C#和JavaScript的理解

    Java.C++.Python.Ruby.PHP.C#和JavaScript和日本动漫里的那些大家熟悉的动漫人物结合起来.依据他们的身世.个人经历来生动的表达各编程语言的发展历程.原文内容例如以下:  ...

  2. Unity光滑与粗糙的材质——相似于生锈的金属表面

    纹理是在Photoshop中制作的,终于效果则是在Unity里得到的.这样的类型的材质.在3D游戏中非经常见.

  3. Install Server Backup Manager on CentOS, RHE, and Fedora

    Skip to end of metadata Added by Internal, last edited by Internal on Aug 25, 2014 Go to start of me ...

  4. Selenium学习(二)入门小例子

    1)打开百度页面 2)输入“hello” 3)点击百度一下按钮 from selenium import webdriver url = "http://" + "www ...

  5. 零基础学python-4.5 标准类型分类

    1.按存储分:原子类型和容器类型 原子类型:仅仅能包括一个对象 容器类型:能够包括多个对象 分类 python类型 原子类型 数值和字符串 容器类型 列表.元组和字典 2.按能否够变化分:可变和不可变 ...

  6. erlang取列表中某个值的位置

    有个需求,比如在一个列表中,取出一个元素的位置,如果出现重复都取出.例如:List = [2,3,10,324,88,29,12],可以求大于某个值的位置,也可以取某个值的位置. 废话少说,直接上代码 ...

  7. git和github菜鸟使用步骤

    刚刚在windows7下安装完git.奉上安装步骤. git安装 安装git程序.运行以下操作: 1. $ cd ~/.ssh    //检查计算机ssh密钥 2.假设没有提示:No such fil ...

  8. Lance老师UI系列教程第九课->高仿比特币监控大师

    http://blog.csdn.net/lancees/article/details/22898971

  9. codevs1032

    题目地址:http://codevs.cn/problem/1032/ 分析: 题目数据有错.这题过不了才正常. 我调了非常久可是就是有两个点过不去.于是我把数据下了下来,找到WA的第五个点和第七个点 ...

  10. (转) 实现wince datagrid 上下滑屏数据浏览

    开发 基于wince 手持设备数据库应用时 由于是触摸屏 当datagrid 数据过多 往往用户烦于去控制又窄又细的上下滚动条 尤其是高分辨率的屏上 (如魅族M8系统 720×480) 而且datag ...