题面在这里!

我们枚举一下第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;
}

ARC-100 D - Equal Cut的更多相关文章

  1. AtCoder Regular Contest 100 Equal Cut

    Equal Cut 思路: 枚举中间那个分界点,然后两边找使得切割后差值最小的点,这个可以用双指针 代码: #include<bits/stdc++.h> using namespace ...

  2. ARC 100

    链接 https://arc100.contest.atcoder.jp/ C Linear Approximation 题解 把ai减去i后排序, 我们要的b就是排完序后的中位数 Code #inc ...

  3. ATcoderARC100D Equal Cut

    ARC100 D - Equal Cut Description: 给出长度为n的序列A,把这个序列分成连续的四段,最小化极差. \(4≤n≤2×10^5,4≤n≤2×10^5\) Solution: ...

  4. Equal Cut

    Equal Cut 题目描述 Snuke has an integer sequence A of length N. He will make three cuts in A and divide ...

  5. AtCoder Regular Contest 100 (ARC100) D - Equal Cut 二分

    原文链接https://www.cnblogs.com/zhouzhendong/p/9251420.html 题目传送门 - ARC100D 题意 给你一个长度为 $n$ 的数列,请切 $3$ 刀, ...

  6. 【AtCoder】 ARC 100

    link C-Linear Approximation 给出\(N\)个数\(A_1,A_2,...,A_N\) ,求一个数\(d\),最小化\(\sum_{i=1}^N|A_i-(d+i)|\) 把 ...

  7. ARC100D Equal Cut

    传送门 分析 首先我们想到的肯定是n^3暴力枚举,但这显然不行.然后我们想到的就是二分了,但这题没有什么单调性,所以二分也不行.这时候我就想到了先枚举找出p2的位置再在它的左右两边找到p1和p3,但是 ...

  8. ARC 100 C - Linear Approximation题解---三分法

    题目链接: https://arc100.contest.atcoder.jp/tasks/arc100_a 分析: 比赛时做这题想到一个瞎搞的方法就是在平均数上下波动一下取最小值,然后大佬yjw学长 ...

  9. canvas对象arc函数的使用-遁地龙卷风

    (-1)写在前面 我用的是chrome49 <canvas id="lol" height="300"></canvas> (1)详细介 ...

随机推荐

  1. bzoj 1588 bst

    用set存下就好了. /************************************************************** Problem: 1588 User: BLADE ...

  2. Django 1.10中文文档-第一个应用Part4-表单和通用视图

    本教程接Part3开始.继续网页投票应用程序,并将重点介绍简单的表单处理和精简代码. 一个简单表单 更新一下在上一个教程中编写的投票详细页面的模板polls/detail.html,让它包含一个HTM ...

  3. python自动开发之第二十四天(Django)

    一.ModelForm操作及验证 1.class Meta:class Meta: #注意以下字段不能加逗号 model = models.UserInfo #这里的all代指所用的字段,也可以是一个 ...

  4. C++ Primer读书笔记

    以前阅读学习C++ Primer时的习题代码(当时代码风格格式比较渣): https://github.com/liyuan989/exercise/tree/master/c%2B%2B%20pri ...

  5. js对页面对float类型的数据格式化处理

    <script>        document.write(parseFloat(<s:property value="assureterm"/>)); ...

  6. python安装基础

    . python安装 //先查看是否存在python的包,如果没有,那可以用yum或去python的官网安装 [root@localhost ~]# rpm -qa|grep python pytho ...

  7. tornado 响应头 中断 状态码 工作流程

    set_header    设置响应头 clear_header 清除响应头 add_header   增加响应头 self.flush  self.finish  中断 set_status     ...

  8. Request对象与Response对象

    1.Request对象 Request对象是来获取请求消息的,是由服务器(Tomcat)创建的. Request对象继承体系结构: ServletRequest        --    接口     ...

  9. django “如何”系列10:如何管理静态文件

    django开发者最关心的是web应用中的动态部分-视图函数和模板.但是明显,web应用还有其他需要注意的部分:静态文件(图片,css,javascript等等),那些都是渲染一个完整的页面需要的东西 ...

  10. Edit Distance——经典的动态规划问题

    题目描述Edit DistanceGiven two words word1 and word2, find the minimum number of steps required to conve ...