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. linux安装openldap步骤

    目录 虚拟机环境:centos 7 一.环境准备 1.关闭 selinux firewalld 临时: setenforce 0  永久: vi /etc/sysconfig/selinux SELI ...

  2. ios 苹果内购订单验证 --- nodejs实现

    实现代码 function IosPlayVerify(data,orderid,cb) { itunesPost(data,function (error,responseData) { if (e ...

  3. POJ:1258-Agri-Net

    Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65322 Accepted: 27029 Descriptio ...

  4. CERC2017 F: Faulty Factorial 简单数论题

    #include <iostream> using namespace std; #define ll long long ; ll n,p,r; ll poww(ll a,ll b){ ...

  5. 笔记-python-调试

    笔记-python-调试 一般在pycharm下调试或使用log查看输出日志,有时小程序不想这么麻烦,也有一些方便使用的调试方式可以使用. 1.      idle调试 1.打开Python shel ...

  6. scala初体验-02

    上一节,我们讲了scala的安装的即一些初步方法,今天,我们来介绍一下scala里面的一些基本操作 1.对于map的的编写,这个是广泛用于Array里面的 val arr = Array(1,2,3, ...

  7. 3195: [Jxoi2012]奇怪的道路

    3195: [Jxoi2012]奇怪的道路 链接 思路: 因为一个点只会和它前后k个点连边,所以,记录下每个点的前k个点和它自己(共k+1个点)的状态,1表示奇数,0表示偶数. dp[i][j][s] ...

  8. 自己定义的TryParse()

    out 参数的练习,自己定义的TryParse()... 一开始写错了,错在:判断str[i] >= '0'&& str[i]<='9'时,把str[i]当数字去判断了.. ...

  9. Installing Nginx With PHP5 (And PHP-FPM) And MySQL Support (LEMP) On Ubuntu 12.04 LTS [repost]

    from : http://www.howtoforge.com/installing-nginx-with-php5-and-php-fpm-and-mysql-support-lemp-on-ub ...

  10. Swift 与众不同的地方

    Swift 与众不同的地方 switch(元组) 特点 其他语言中的switch语句只能比较离散的整形数据(字符可以转换成整数) 但是swift中可以比较整数.浮点数.字符.字符串.和元组数据类型,而 ...