题面在这里!

我们枚举一下第2和第3段的分界点,显然这种情况下 第1与第2  和  第3与第4  之间的分界点都只有两种情况可能最优,吧这四种情况讨论一下就好了。

两边的分界点可以单调扫过去。。。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
const int N=200005; inline int read(){
int x=0; char ch=getchar();
for(;!isdigit(ch);ch=getchar());
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return x;
} int n,px,py;
ll a[N],ans=1e18,tot,now,mx,mn; inline void update(){
if(now<mn) mn=now;
else if(now>mx) mx=now;
} inline void solve(){
for(int i=1;i<=n;i++){
while(px<i&&a[px+1]*2ll<=a[i]) px++;
while(py<n&&a[py+1]*2ll<=tot+a[i]) py++; for(int u=px+1;u>=px;u--)
for(int v=py+1;v>=py;v--){
mx=mn=a[u]; now=a[i]-a[u],update();
now=a[v]-a[i],update();
now=tot-a[v],update(); ans=min(ans,mx-mn);
}
}
} int main(){
n=read();
for(int i=1;i<=n;i++) a[i]=a[i-1]+(ll)read();
a[n+1]=a[n+2]=tot=a[n];
solve(),printf("%lld\n",ans);
return 0;
}

最新文章

  1. 基于MQTT协议进行应用开发
  2. PHP基础面试题
  3. .NET跨平台:在Linux Ubuntu上编译coreclr/corefx/dnx(20150617)
  4. 深入理解Javascript--作用域和赋值操作
  5. SpringMvc-Httl-shiro的整合
  6. python成长之路【第六篇】:python模块--time和datetime
  7. PHP--字符串处理函数
  8. 用sql获取某字符串中的数字部分的语句
  9. arcengine9.3与10开发授权代码
  10. Spark的任务处理流程
  11. Windows2003 下 MySQL 数据库每天自动备份
  12. 关于jquery文件上传插件 uploadify 3.1的使用
  13. fgets的用法
  14. 小米平板6.0系统如何无ROOT激活xposed框架的步骤
  15. vue-nuxtjs
  16. 【BZOJ】2734: [HNOI2012]集合选数
  17. day23(事务管理)
  18. Future接口和Callable接口以及FeatureTask详解
  19. 一起来点React Native——常用组件之Touchable系列
  20. 问题解决:在此页上的ActiveX控件

热门文章

  1. Vue 键盘事件
  2. JDBC+Servlet+JSP实现基本的增删改查(简易通讯录)
  3. C/C++中手动获取调用堆栈【转】
  4. jQuery 中的 unbind() 方法
  5. ora11g listener.ora
  6. python的多线程、多进程代码示例
  7. AtomicReference 和 volatile 的区别
  8. python运行原理/python解释器
  9. SQL Server 用链接服务器 同步SqlServer与MySQL
  10. K8S的APISERVER,应用了HTTPS之后,命令行如何访问?