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