好端端的被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的更多相关文章

  1. HDU 5191 Building Blocks

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5191 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  2. BestCoder Round #34_1002 以及 hdu 5191

    枚举最终的W堆积木在哪,确定了区间,那么就需要把高于H的拿走,低于H的补上,高处的积木放到矮的上面,这样最优. 注意多出来的积木可以放在已有积木的前面或者后面,独立成一堆积木,所以需要在n堆积木的前后 ...

  3. hdu 5191(思路题)

    Building Blocks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. HDU—— 5159 Building Blocks

    Problem Description After enjoying the movie,LeLe went home alone. LeLe decided to build blocks. LeL ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. iOS网络开发工具集----字符串操作和时间操作

    一.字符串的操作方法 #pragma mark - 创建字符串 - (void)CreatString { // <1> 创建字符串 NSString *strS = @"Thi ...

  2. 新建项目git clone

  3. [Apple开发者帐户帮助]二、管理你的团队(7)管理服务器帐户

    如果在配置机器人以在多个设备上运行应用程序时向团队添加服务器,允许Xcode Server为您管理签名,或者配置机器人以创建iOS App文件,则服务器可以访问您的资产并显示在您的开发人员帐户 您可以 ...

  4. [Apple开发者帐户帮助]二、管理你的团队(2)更改团队成员角色

    如果您已加入Apple开发者计划,您将在App Store Connect中管理团队成员.有关详细信息,请转到App Store Connect帮助中的添加和编辑用户. 如果您已加入Apple Dev ...

  5. Jmeter_Beanshell解析并提取json响应

    1:前置条件 将fastjson-1.2.49.jar包置于jmeter的lib目录下,并将该jar包添加到测试计划的Library中:否则会报:Typed variable declaration ...

  6. ACM_一道耗时间的水题

    一道耗时间的水题 Time Limit: 2000/1000ms (Java/Others) Problem Description: Do you know how to read the phon ...

  7. 树莓派-基于raspistill实现定时拍照

    raspistill 经过上一篇<<树莓派-安装摄像头模块>>之后 raspistill 是树莓派基于摄像头拍照命令 比如我要截取一张宽1024px,高768px,旋转180度 ...

  8. Obsolete---标记方法 类过期

    最近做一个接口的修改,由于是很老的接口,不太了解外部有多少地方引用了它. 但是内部的方法由于业务发展已经不太适合现在的需求,想改又不该动.所以想到了如果设置为过期. Obsolete 属性将某个程序实 ...

  9. Windows7环境下Composer 安装包的Cache目录位置

    http://segmentfault.com/a/1190000000355928 https://getcomposer.org/doc/ 要说Composer的用法,以后再说,现在只记录wind ...

  10. border使用

    border属性 border-width  border-style  border-color  inherit border-style的值:none  dotted(点线)  dashed(虚 ...