题目链接:Codeforces 460C Present
题目大意:有n盆花,可以浇m次水,每次浇水的范围为w,被浇到水的花长高1米,问说可以使最矮的花的最高值是多少
解题思路:二分答案,遍历判断一遍。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5+5;
const int inf = 1e9+maxn;
int N, M, W, arr[maxn], v[maxn];
bool judge (int k) {
int ti = M, n = 0;
memset(v, 0, sizeof(v));
for (int i = 1; i <= N; i++) {
n += v[i];
int tmp = max(k - arr[i] - n, 0);
ti -= tmp;
if (ti < 0)
return false;
if (i + 1 <= N)
v[i+1] += tmp;
if (i + W <= N)
v[i+W] -= tmp;
}
return true;
}
int bsearch (int l, int r) {
for (int i = 0; i < 80; i++) {
int mid = (r + l) / 2;
if (judge(mid))
l = mid;
else
r = mid;
}
return l;
}
int main () {
scanf("%d%d%d", &N, &M, &W);
for (int i = 1; i <= N; i++)
scanf("%d", &arr[i]);
printf("%d\n", bsearch(1, inf));
return 0;
}
分享到:
相关推荐
codeforces编程网站预测分数插件
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
暴枚最长桌脚的长度$l$,然后长度比$l$长的桌脚全部都要砍掉长度比$l$短的桌脚选择代价前$k$小的砍掉用线段树维护;示例程序 :typedef long l
Codeforces 185A - Plant 全测试点49个
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
Some of the Codeforces problems codes
Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B.
Codeforces round 678 D2_Codeforces_源码
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
打codeforces的神器
一个Codeforces、牛客竞赛、AtCoder平台的编程竞赛查询插件,ACMer必备.zip
codeforces-js Codeforces JS
题目大意:给出一个数列 a ,求出 题目分析:如果暴力的话显然时间复杂度是 n * n 的,我们应该想办法去优化,比赛的时候想用线段树,但是不会在维护异或的前提下区间加法,也想过用矩阵维护,但丝毫没什么用呀,...
使用 C# + WPF 开发 --- 还在发愁打了那么多场比赛都没有进入首页么? 还在为了前 5 的 hacker 名额阅读千份代码么? 是的,你没有看错! 这是一个 Edu & Div.3 轮 Open hacking 错误代码自动查找器!...
Codeforces Round #723 (Div. 2).md
Codeforces 题库 201-294 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。