HDU 5191
好端端的被HACK掉了。。。应该是在两端都要补W个0才对,之前只想到要在后面补足0,没想到前面也应该补足,因为前面即便存在0也可能使得移动的积木数最少。。
T_T
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std; LL height[150005];
LL in[150005];
LL out[150005]; LL mint(LL a,LL b){
if(a<b) return a;
return b;
}
LL maxt(LL a,LL b){
if(a>b) return a;
return b;
} int main(){
LL n,w,h;
while(scanf("%I64d%I64d%I64d",&n,&w,&h)!=EOF){
LL sum=0;
memset(height,0,sizeof(height));
for(LL i=w+1;i<=n+w;i++){
scanf("%I64d",&height[i]);
sum+=height[i];
}
if(sum<w*h) puts("-1");
else{
n=n+w+w;
in[0]=out[0]=0;
LL ans=(1ll<<62);
for(LL i=1;i<=n;i++){
if(height[i]>=h){
out[i]=out[i-1]+height[i]-h;
in[i]=in[i-1];
}
if(height[i]<=h){
in[i]=in[i-1]+h-height[i];
out[i]=out[i-1];
}
if(i-w>=0){
ans=mint(ans,maxt(in[i]-in[i-w],out[i]-out[i-w]));
}
}
printf("%I64d\n",ans);
}
}
return 0;
}
HDU 5191的更多相关文章
- HDU 5191 Building Blocks
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5191 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- BestCoder Round #34_1002 以及 hdu 5191
枚举最终的W堆积木在哪,确定了区间,那么就需要把高于H的拿走,低于H的补上,高处的积木放到矮的上面,这样最优. 注意多出来的积木可以放在已有积木的前面或者后面,独立成一堆积木,所以需要在n堆积木的前后 ...
- hdu 5191(思路题)
Building Blocks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU—— 5159 Building Blocks
Problem Description After enjoying the movie,LeLe went home alone. LeLe decided to build blocks. LeL ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- Coursera Algorithms week3 快速排序 练习测验: Nuts and bolts
题目原文: Nuts and bolts. A disorganized carpenter has a mixed pile of n nuts and n bolts. The goal is t ...
- 练习2 及pl/sql
Rownum 如果不是对主键排序是不会变得 -查询没有学分的学生信息 --SELECT * FROM z_student zs WHERE zs.code NOT IN (SELECT DISTINC ...
- Redis(四)-配置
Redis 配置 Redis 的配置文件位于 Redis 安装目录下,文件名为 redis.conf. 你可以通过 CONFIG 命令查看或设置配置项. 语法 Redis CONFIG 命令格式如下: ...
- SQL Server跨库跨服务器访问实现
我们经常会遇到一个数据库要访问另一个数据库,或者一台服务器要访问另一台服务器里面的数据库. 那么这个如何实现的呢? 相信看完这篇文章你就懂了! 同一台服务器跨库访问实现 1. 首先创建两个数据库Cro ...
- WPF TextBox 仅允许输入数字
因为在 IValueConverter 实现中,当文本不能转换为目标类型时返回 DependencyProperty.UnsetValue ,Validation.GetHasError 返回 tru ...
- # --with-http_stub_status_module模块
作用: 查看nginx的客户端状态 环境检测 nginx -V 查看nginx已经编译的模块中是否包含--with-http_stub_status_module 语法: 效果
- HTML简单入门
- Java攻城狮学习路线 - 基本结构 标准文档:www.w3.org <!DOCTYPE html> <html> <head> <meta charse ...
- 2.0 Linux系统的安装之Fedora安装单系统(2)
2.0 Linux系统的安装之Fedora安装单系统(2) *Linux系统的安装之Fedora安装单系统 恐怕最好装的系统就是Linux系统了,或者与Windows并列.此篇教程为Fedora的单系 ...
- Clustered Index Scan 与 Clustered Index Seek
Clustered Index Scan 与 Clustered Index Seek 在利用 SQL Server 查询分析器的执行计划中,会有许多扫描方式,其中就有 Clustered Index ...
- jstl与el结合常见用法
JSTL Functions标签库 在JSP文件中使用Functions标签库,要先通过taglib指令引入该标签库: <%@taglib uri=”http://java.sun.com/js ...