time limit per test 1 second

memory limit per test 256 megabytes

input standard input

output standard output

You are given an array of n integer numbers. Let sum(l, r) be the sum of all numbers on positions from l to r non-inclusive (l-th element is counted, r-th element is not counted). For indices l and r holds 0 ≤ l ≤ r ≤ n. Indices in array are numbered from 0.

For example, if a = [ - 5, 3, 9, 4], then sum(0, 1) =  - 5, sum(0, 2) =  - 2, sum(1, 4) = 16 and sum(i, i) = 0 for each i from 0 to 4.

Choose the indices of three delimiters delim0, delim1, delim2 (0 ≤ delim0 ≤ delim1 ≤ delim2 ≤ n) and divide the array in such a way that the value of res = sum(0, delim0) - sum(delim0, delim1) + sum(delim1, delim2) - sum(delim2, n) is maximal.

Note that some of the expressions sum(l, r) can correspond to empty segments (if l = r for some segment).

Input

The first line contains one integer number n (1 ≤ n ≤ 5000).

The second line contains n numbers a0, a1, ..., an - 1 ( - 109 ≤ ai ≤ 109).

Output

Choose three indices so that the value of res is maximal. If there are multiple answers, print any of them.

Examples

input

3
-1 2 3

output

0 1 3

input

4
0 0 -1 0

output

0 0 0

input

1
10000

output

1 1 1
 
【翻译】给出一个长度为n的序列(1~n),现在需要选择三个点d1,d2,d2(0<=d1<=d2<=d3<=n),设ABCD分别为区间(0,d1],(d1,d2],(d2,d3],(d3,n]的内部元素和,求A-B+C-D取到最大值时d1,d2,d3的值,情况多种就随便输出一种。
 
题解:
①好像怎么弄都是O(n2),枚举d2,然后取d1,d3的最有位置更新答案。
    ②为辅助上述方法,预处理(A-B),(C-D)的最大值,并记录取最大值时候d的位置。
    ③预处理会使用到前缀和。
#include<stdio.h>
#define ll long long
#define comb (val1[i]+val2[i])
#define S(l,r) (sum[r]-sum[l-1])
#define go(i,a,b) for(int i=a;i<=b;i++)
const int N=5003;int n,p1[N],p3[N],P1,P2,P3;
ll a[N],_[N],sum[N],val1[N],val2[N],ans,t;
int main()
{
scanf("%d",&n);ans=1ll*-1e9*1e9; go(i,1,n)scanf("%I64d",a+i),sum[i]=sum[i-1]+a[i];
go(i,0,n){val1[i]=1ll*-1e9*1e9;
go(j,0,i)if((t=S(1,j)-S(j+1,i))>val1[i])p1[i]=j,val1[i]=t;}
go(i,0,n){val2[i]=1ll*-1e9*1e9;
go(j,i,n)if((t=S(i+1,j)-S(j+1,n))>val2[i])p3[i]=j,val2[i]=t;}
go(i,0,n)if(val1[i]+val2[i]>ans)ans=comb,P1=p1[i],P2=i,P3=p3[i]; printf("%d %d %d\n",P1,P2,P3);return 0;
}//Paul_Guderian
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

挥挥手倦鸟飞过丛林,隐没在碎与溃的深谷。——————汪峰《挥挥手》

【CF Edu 28 C. Four Segments】的更多相关文章

  1. 【CF Edu 28 A. Curriculum Vitae】

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  2. 【CF Edu 28 B. Math Show】

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  3. 【2020.11.28提高组模拟】T1染色(color)

    [2020.11.28提高组模拟]T1染色(color) 题目 题目描述 给定 \(n\),你现在需要给整数 \(1\) 到 \(n\) 进行染色,使得对于所有的 \(1\leq i<j\leq ...

  4. 【CF edu 30 D. Merge Sort】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  5. 【Cf edu 30 B. Balanced Substring】

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  6. 【CF Round 434 B. Which floor?】

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  7. 【2020.11.28提高组模拟】T2 序列(array)

    序列(array) 题目描述 ​给定一个长为 \(m\) 的序列 \(a\). 有一个长为 \(m\) 的序列 \(b\),需满足 \(0\leq b_i \leq n\),\(\sum_{i=1}^ ...

  8. B. Lost Number【CF交互题 暴力】

    B. Lost Number[CF交互题 暴力] This is an interactive problem. Remember to flush your output while communi ...

  9. 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)

    A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...

随机推荐

  1. STL 之 set的应用

    关于set Set是STL中的一个容器,特点是其中包含的元素值是唯一的,set根据其底层实现机制分为hash存储和红黑树存储两种方式,这两种结构最本质的区别就是有序和无序,红黑树的存储是有序的而has ...

  2. 【MYSQL笔记2】复制表,在已有表的基础上设置主键,insert和replace

    之前我自己建立好了一个数据库xscj:表xs是已经定义好的 具体的定义数据类型如下: 为了复制表xs,我们新建一个表名为xstext,使用下列语句进行复制xs,或者说是备份都可以: create ta ...

  3. Linux进程通信之匿名管道

    进程间的通信方式 进程间的通信方式包括,管道.共享内存.信号.信号量.消息队列.套接字. 进程间通信的目的 进程间通信的主要目的是:数据传输.数据共享.事件通知.资源共享.进程控制等. 进程间通信之管 ...

  4. tar工具(打包,压缩)

    tar工具(打包,压缩)========================= tar打包工具 -c:表示建立一个tar包或者压缩文件包-x:表示解包或者解压缩-v:表示可视化-f: 后面跟文件名(即-f ...

  5. 使用命令行设置MySql编码格式

    使用命令行设置MySql编码格式 1.登录mysql 2.输入 SHOW VARIABLES LIKE 'character_set_%'; 3.查看 value值是否为utf8,如果不是,则使用SE ...

  6. elasticsearch 5.x 系列之一 开始安装啦

    以下是镇楼用的,各路退让,我要吹liubi 了 // // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ...

  7. Dialog BLE 学习之 修改分散加载文件 (2)

    最近搞Dialog的BLE SDK,发现空间不够了,询问原厂,得知可以通过调整分散加载文件而增加空间,一方面是有42KB+8KB的硬件基础,另一方面是原有的程序限制为38KB+8KB.故顺便学习了下把 ...

  8. ACE handle_timeout 事件重入

    当多线程运行反应器事件时, 注意handle_timeout会重入,单独线程不存在下列问题! 1. 一个timer事件 // test_ace_timer.cpp : Defines the entr ...

  9. centos使用--rpm和yum的关系以及基本用法

    1 RPM包 RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的"添加/删除程序" rpm 执行安装包 二进制包(Binar ...

  10. ARC下还会存在内存泄露吗?

    1.第三方框架不正当使用.2.block,delegate,NSTimer循环使用.3.非oc对象的内存处理.4.地图类处理.5.大次数循环内存暴涨. 非oc对象的释放: 例如使用CGImageRel ...