题目:

C. Present
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 w contiguous
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 test(s)
input
6 2 3
2 2 2 2 1 1
output
2
input
2 5 1
5 8
output
9
Note

In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get
height 3 in this test.

题意分析:

二分答案。然后check一下。

代码借用的别人的,自己的太丑。


代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; const int inf=1<<30;
const int maxn=2e5+100; int n,m,w,a[maxn];
int tot[maxn];
bool check(int val)
{
memset(tot,0,sizeof(tot));
int now=0,res=m;
for(int i=1;i<=n;i++)
{
now+=tot[i];
if(a[i]+now<val)
{
res-=val-a[i]-now;
if(res<0)
return false;
tot[i+w]-=val-a[i]-now;
now+=val-a[i]-now;
}
}
return true;
}
int main()
{
while(scanf("%d%d%d",&n,&m,&w)!=EOF)
{
memset(tot,0,sizeof(tot));
int l=0,r=inf;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
r=max(a[i],r);
}
int ans=0;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid))
{
ans=mid;
l=mid+1;
}
else
r=mid-1;
}
printf("%d\n",ans);
}
return 0;
}

Codeforces Round #262 (Div. 2) C的更多相关文章

  1. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  2. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  3. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

  4. codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/460/A题意:Vasya每天用掉一双袜子,她妈妈每m天给他送一双袜子,Vasya一开始有n双袜子, ...

  5. Codeforces Round #262 (Div. 2) E. Roland and Rose 暴力

    E. Roland and Rose Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...

  6. Codeforces Round #262 (Div. 2)解题报告

    详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http ...

  7. Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

    题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second mem ...

  8. Codeforces Round #262 (Div. 2)

    A #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  9. Codeforces Round #262 (Div. 2) A B C

    题目链接 A. Vasya and Socks time limit per test:2 secondsmemory limit per test:256 megabytesinput:standa ...

  10. Codeforces Round #262 (Div. 2) 二分+贪心

    题目链接 B Little Dima and Equation 题意:给a, b,c 给一个公式,s(x)为x的各个位上的数字和,求有多少个x. 分析:直接枚举x肯定超时,会发现s(x)范围只有只有1 ...

随机推荐

  1. 关于block的回调使用-防止内存泄露问题

    block 一般用于回调,比方请求数据我们把asi封装好,仅仅用block调数据就方便很多 获取到得数据假设要给之加入数据,切记不能够使用self.(这个数组) 或者_(这个数组) addObject ...

  2. 防盗链Nginx设置图片防盗链,设置无效的请仔细看红字

    *******************************************************************切记,替换的图片地址要使用没有防盗链的网站图片,否则由于替换的图片 ...

  3. AIDL旅行记之开篇AIDL基本介绍

    嗨,伙伴们,计划了一周的想法最终要在这一刻实现了. 一直都想写一个博客专栏,但是总是鼓不起勇气来写.感觉自己的水量还不太够.哈哈.这次下定决心,与小伙伴们一起分享下Android中的AIDL,从此,也 ...

  4. Ubuntu下配置jdk及maven等方法

    从/etc/profile文件代码得知系统启动会把/etc/profile.d目录下面所有的.sh文件进行加载,如果在其中新建.sh文件用来设立环境变量等,系统启动后也会加载到它们.另外一种方法就是修 ...

  5. ZH奶酪:IBG项目工作内容

    IBG项目技术概览 (HTML/CSS/JavaScript/AngularJS/PHP/MySQL): (1)后台:PHP Yii2.0 Framework (2)前端:Ionic Framewor ...

  6. WebService 之 身份验证

    在项目开发,我们经常会使用WebService,但在使用WebService时我们经常会考虑到了WebService是安全问题,很容易想到通过一组用户名与密码来防止非法用户的调用 . 一.Networ ...

  7. Java从零开始学十一(类和对象)

    一.面象对象 二.什么是类 我肯定说,不知道.不清楚. 简单讲类是java中的基本单元,类是具有相同特性和行为的对象集合 三.类的定义 3.1.类的定义 class 类名称{ 数据类型  属性 ; … ...

  8. 如何在hosts文件添加自己想要解析的网站?及修改hosts的作用

    http://union.zhuna.cn/help/144.asp 在Windows2003/XP系统中位于C:\Winnt\System32\Drivers\Etc 目录中,找到host文件. 首 ...

  9. 寻找SQL注入点

    如果要对一个网站进行SQL注入攻击,首先就需要找到存在SQL注入漏洞的地方,也就是寻找所谓的注入点.可能的SQL注入点一般存在于登录页面.查找页面或添加页面等用户可以查找或修改数据的地方. 最常用的寻 ...

  10. jQuery中first-child与first选择器区别

    1.first-child first-child为每个父级元素匹配第一个子元素,可以匹配出多个元素: 示例代码: <!DOCTYPE html> <html lang=" ...