题目大意:有$n$个点,每个点最开始有$a_i$个弓箭手,在第$i$个位置的弓箭手可以给$[i-r,i+r]$区间加上$1$的防御,你还有$k$个弓箭手,要求你最大化最小防御值

题解:二分答案,从右向左扫,显然得知,给一个位置增加防御值最好方式是在最右段加一些弓箭手。

卡点:

C++ Code:

#include <cstdio>
#define maxn 500010
const long long inf = 0x3f3f3f3f3f3f3f3f;
int n, R;
long long k, protect1[maxn], s[maxn], protect2[maxn], protect3[maxn], p[maxn], protect4[maxn];
inline int min(int a, int b) {return a < b ? a : b;}
inline bool check(long long mid) {
__builtin_memset(p, 0, sizeof p);
int l = -R, r = R;
long long now = 0, K = k;
for (int i = 0; i < r; i++) now += s[i];
for (int i = 0; i < n; i++) {
now += s[r], now -= s[l - 1] + p[l - 1];
if (now < mid) {
p[r] = mid - now;
K -= p[r];
if (K < 0) return false;
now = mid;
}
r++, l++;
}
return true;
}
int main() {
scanf("%d%d%lld", &n, &R, &k);
for (int i = 0; i < n; i++) scanf("%lld", s + i);
long long l = 0, r = inf, ans;
while (l <= r) {
long long mid = l + r >> 1;
if (check(mid)) {
l = mid + 1;
ans = mid;
} else r = mid - 1;
}
printf("%lld\n", ans);
return 0;
}

  

[CF954G]Castle Defense的更多相关文章

  1. Educational Codeforces Round 40 G. Castle Defense (二分+滑动数组+greedy)

    G. Castle Defense time limit per test 1.5 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces 954 G. Castle Defense

    http://codeforces.com/problemset/problem/954/G 二分答案 检验的时候,从前往后枚举,如果发现某个位置的防御力<二分的值,那么新加的位置肯定是越靠后越 ...

  3. [CodeForces954G]Castle Defense(二分答案+差分)

    Description 题目链接 Solution 二分答案,套一个差分标记即可 每次放弓箭手显然越右边越优 Code #include <cstdio> #include <alg ...

  4. Educational Codeforces Round 40 (Rated for Div. 2) 954G G. Castle Defense

    题 OvO http://codeforces.com/contest/954/problem/G 解 二分答案, 对于每个二分的答案值 ANS,判断这个答案是否可行. 记 s 数组为题目中描述的 a ...

  5. Educational Codeforces Round 40 (Rated for Div. 2) Solution

    从这里开始 小结 题目列表 Problem A Diagonal Walking Problem B String Typing Problem C Matrix Walk Problem D Fig ...

  6. Educational Codeforces Round 40 A B C D E G

    A. Diagonal Walking 题意 将一个序列中所有的\('RU'\)或者\('UR'\)替换成\('D'\),问最终得到的序列最短长度为多少. 思路 贪心 Code #include &l ...

  7. Castle Core 4.0.0 alpha001发布

    时隔一年多以后Castle 项目又开始活跃,最近刚发布了Castle Core 4.0.0 的alpha版本, https://github.com/castleproject/Core/releas ...

  8. 对Castle Windsor的Resolve方法的解析时new对象的探讨

    依赖注入框架Castle Windsor从容器里解析一个实例时(也就是调用Resolve方法),是通过调用待解析对象的构造函数new一个对象并返回,那么问题是:它是调用哪个构造函数呢? 无参的构造函数 ...

  9. AOP之Castle DynamicProxy 动态代理

    这里主要介绍使用castle这个动态代理,在.net一些开源的框架里可以找到它的影子,就连微软的rchard也是使用这个进行方法拦截等可以基于这个进行方法拦截,在这个方面PostSharp算是比较好用 ...

随机推荐

  1. 重新认识下数组的concat方法

    最近在学习react,看官方文档的时候,有一个例子中的一句话让我困惑.就是讲todoList的例子 concat不是连接数组的吗?看了一下concat的介绍 数组虽然是对象类型,但是对象毕竟不是数组啊 ...

  2. P2661 信息传递 DFS

    题目链接:洛谷 P2661 信息传递 一个人要想知道自己的生日,就意味着信息的传递是成环的,因为每轮信息只能传递一个人,传递的轮数就等于环的大小 环的大小就等于环中的两个点到第三个点的距离之和加一,我 ...

  3. C/C++获取本机名+本机IP+本机MAC

    本机名.IP.MAC都是一些比较常用网络参数,怎么用C/C++获取呢? 研究了两三个小时... 需要说明的都在代码注释里 #include <stdio.h> #include <W ...

  4. POJ2154 Color(Polya定理)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11654   Accepted: 3756 Description Bead ...

  5. TCL之表达式

  6. css 自动换行,超出省略号代替

    overflow : hidden;    text-overflow: ellipsis;    display: -webkit-box;    -webkit-line-clamp: 2;    ...

  7. django-simple-captcha

    在注册页面生成验证码的时候,出现错误如下: build_attrs() takes from 1 to 2 positional arguments but 3 were given, 不知道为什么报 ...

  8. python-7面向对象高级编程

    1-给类动态增加方法 class Student(object): pass def set_score(self, score): self.score = score Student.set_sc ...

  9. 笔记-python异常信息输出

    笔记-python异常信息输出 1.      异常信息输出 python异常捕获使用try-except-else-finally语句: 在except 语句中可以使用except as e,然后通 ...

  10. talent-aio源码阅读小记(二)

    我们上一篇提到了talent-aio的四类Task:DecodeRunnable.HandlerRunnable.SendRunnable.CloseRunnable,并且分析了这些task的基类Ab ...