Feel Good
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 8753   Accepted: 2367
Case Time Limit: 1000MS   Special Judge

Description

Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent people's memories about some period of life.

A new idea Bill has recently developed assigns a non-negative integer value to each day of human life.

Bill calls this value the emotional value of the day. The greater the emotional value is, the better the daywas. Bill suggests that the value of some period of human life is proportional to the sum of the emotional values of the days in the given period, multiplied by the smallest emotional value of the day in it. This schema reflects that good on average period can be greatly spoiled by one very bad day.

Now Bill is planning to investigate his own life and find the period of his life that had the greatest value. Help him to do so.

Input

The first line of the input contains n - the number of days of Bill's life he is planning to investigate(1 <= n <= 100 000). The rest of the file contains n integer numbers a1, a2, ... an ranging from 0 to 106 - the emotional values of the days. Numbers are separated by spaces and/or line breaks.

Output

Print the greatest value of some period of Bill's life in the first line. And on the second line print two numbers l and r such that the period from l-th to r-th day of Bill's life(inclusive) has the greatest possible value. If there are multiple periods with the greatest possible value,then print any one of them.

Sample Input

6
3 1 6 4 5 2

Sample Output

60
3 5

Source

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top

 /*
题意:10^5个数字,求max { 区间[ ] * 该区间最小值 };
解决思路:
找区间最小值,如果能够求出其长度,那么就可以扫一遍解决。
关键在于找区间最小值。
而且存在一种情况,同一个值,会是许多区间的最小值。
所以,转化一下,求每一个i为最小值的时候,能到到达的最远位置。 */ #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; int a[],b[];
__int64 s[];
int L[],R[];
typedef struct
{
int num;
int rp;
}Queue;
Queue q[],tmp; int main()
{
int n,i;
int head,tail,Num,l,r,lx,rx;
__int64 hxl,tom;
while(scanf("%d",&n)>)
{
for(i=,s[]=;i<=n;i++)
{
scanf("%d",&a[i]);
b[n-i+]=a[i];
s[i]=s[i-]+a[i];
}
memset(L,-,sizeof(L));
memset(R,-,sizeof(R));
head=;tail=-;
for(i=;i<=n;i++)
{
tmp.num=i;
tmp.rp=a[i];
while( head<=tail && q[tail].rp>tmp.rp )
{
if( R[q[tail].num]==-)
{
R[q[tail].num]= i - q[tail].num-;
}
tail--;
}
q[++tail]=tmp;
}
while( head<=tail )
{
Num=q[tail].num-q[head].num;
if( R[q[head].num]==-)
{
R[q[head].num]=Num;
}
head++;
}
head=;tail=-;
for(i=;i<=n;i++)
{
tmp.num=i;
tmp.rp=b[i];
while( head<=tail && q[tail].rp>tmp.rp )
{
Num=n-q[tail].num+;
if( L[Num]==-)
L[Num]= i - q[tail].num-;
tail--;
}
q[++tail]=tmp;
}
while( head<=tail )
{
Num=n-q[head].num+;
if( L[Num]==-)
{
L[Num]=q[tail].num-q[head].num;
}
head++;
}
for(tom=-,i=;i<=n;i++)
{
l=i-L[i];
r=i+R[i];
hxl=(s[r]-s[l-])*a[i];
if( hxl>tom)
{
tom=hxl;
lx=l;
rx=r;
}
}
printf("%I64d\n%d %d\n",tom,lx,rx);
}
return ;
}

poj 2796 Feel Good 单调队列的更多相关文章

  1. POJ 2823 Sliding Window + 单调队列

    一.概念介绍 1. 双端队列 双端队列是一种线性表,是一种特殊的队列,遵守先进先出的原则.双端队列支持以下4种操作: (1)   从队首删除 (2)   从队尾删除 (3)   从队尾插入 (4)   ...

  2. poj 2823 Sliding Window (单调队列入门)

    /***************************************************************** 题目: Sliding Window(poj 2823) 链接: ...

  3. poj 1821 Fence(单调队列优化DP)

    poj 1821 Fence \(solution:\) 这道题因为每一个粉刷的人都有一块"必刷的木板",所以可以预见我们的最终方案里的粉刷匠一定是按其必刷的木板的顺序排列的.这就 ...

  4. POJ 2823 滑动窗口 单调队列模板

    我们从最简单的问题开始: 给定一个长度为N的整数数列a(i),i=0,1,...,N-1和窗长度k. 要求: f(i) = max{a(i-k+1),a(i-k+2),..., a(i)},i = 0 ...

  5. POJ 3709 K-Anonymous Sequence (单调队列优化)

    题意:给定一个不下降数列,一个K,将数列分成若干段,每段的数字个数不小于K,每段的代价是这段内每个数字减去这段中最小数字之和.求一种分法使得总代价最小? 思路:F[i]表示到i的最小代价.f[i]=m ...

  6. POJ 2823 滑动窗口 单调队列

    https://vjudge.net/problem/POJ-2823 中文:https://loj.ac/problem/10175 题目 给一个长度为 $N$ 的数组,一个长为 $K$ 的滑动窗体 ...

  7. POJ 2823 Sliding Window (单调队列)

    单调队列 加了读入挂比不加更慢.... 而且这份代码要交c++ 有大神G++跑了700ms..... orzorzorz #include<iostream> #include<cs ...

  8. poj 3162 树DP+单调队列

    http://acm.hust.edu.cn/vjudge/problem/11552 http://blog.csdn.net/woshi250hua/article/details/7727677 ...

  9. poj 2823 Sliding Windows (单调队列+输入输出挂)

    Sliding Window Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 73426   Accepted: 20849 ...

随机推荐

  1. Get 和 Post 方法的选择和URL的设计

    原文链接:http://yifei.me/note/540 HTTP 中常用的方法有 GET/POST/PUT/DELETE 等,在设计API或者表单的时候我们需要选择合适的方法.一般有两种方案: 只 ...

  2. java使用Redis7--分布式存储并实现sentinel主从自动切换

    前面实现了分布式存储,也实现了sentinel单点故障时主从自动切换,现在还需要一种机制,实现分布式存储下,单点故障时的主从自动切换. Server配置 # cd /usr/redis/src/tes ...

  3. 如何在CentOS 7上使用vsftpd设置ftp服务器

    一.前言介绍 FTP(文件传输协议)是一种标准的客户机-服务器网络协议,允许用户在远程网络之间传输文件. 有几个开源的FTP服务器可用于Linux.最受欢迎和广泛使用的是pureftpd.proftp ...

  4. java简单的运算符和表达式

    1.运算符的运算级别分为很多层,第一层是(),括号的运算级别最高. 第二层是+,——,*,/,加,减,乘,除 第三层是==,等于号. 第四层是&&,||,或 与 且 && ...

  5. C#-WebForm-★★★JQuery-动画★★★

    1.show(),hide() 瞬间显示或隐藏,隐藏后不占有位置 2.slideDown(),slideUp() 向下拉伸显示,向上缩减隐藏 3.fadeIn(),fadeOut() 渐显或渐隐,隐藏 ...

  6. 【kuangbin】计算几何部分最新模板

    二维几何部分 // `计算几何模板` ; const double inf = 1e20; const double pi = acos(-1.0); ; //`Compares a double t ...

  7. noip | 题目 | noip数据 收集站 | noipdata

    这是什么 一个NOIP历年比赛数据及题目的收集站,方便大家查找使用 网站链接:https://noipdata.github.io 点击这里立即跳转 新连接:noipdata.rcxzsc.com 点 ...

  8. WPF实现WORD 2013墨迹批注功能

    1 前言 WORD 2013可以使用墨迹在文档上面标注,本文讲述通过WPF第三方控件实现类似主要功能如下: 名称 描述 墨迹标注 不论是否触摸屏环境下可以开始墨迹功能,并实现鼠标/触摸在文档任意位置绘 ...

  9. 用Python写了一个postgresql函数,感觉很爽

    用Python写了一个postgresql函数,感觉很爽 CREATE LANGUAGE plpythonu; postgresql函数 CREATE OR REPLACE FUNCTION myfu ...

  10. Django中-事务操作

    如何在Django中进行事务操作呢? 近期,公司里要使用Django开发一套金融相关的系统. 涉及钱了.....安全安全安全 如果钱转到一半,系统崩了,咋办? 如果钱汇到一半,系统崩了,咋办? 如果东 ...