zoukankan      html  css  js  c++  java
  • ARC-100 D

    题面在这里!

        我们枚举一下第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
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    IDEA添加注释模板
    Docker安装Mysql
    Linux使用
    Linux使用
    Spring Cloud入门 (5)
    在IDEA中将SpringBoot项目打包成jar包
    Linux使用
    Linux使用
    Linux使用- 虚拟机安装 Linux
    Spring Cloud入门 (4)
  • 原文地址:https://www.cnblogs.com/JYYHH/p/9253162.html
Copyright © 2011-2022 走看看