http://poj.org/problem?id=2796

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 15375   Accepted: 4252
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

 
处理前缀和以及当前点向左最大数的位置和向右最大数的位置
 #include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; #define LL long long
const int N(+);
int ans_l,ans_r,l[N],r[N];
LL n,ans_val=-,sum[N],val[N]; inline void read(LL &x)
{
x=; LL ch=getchar();
for(;ch>''||ch<'';) ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=ch-''+x*;
} int main()
{
read(n);
for(int i=;i<=n;i++)
{
read(val[i]),l[i]=r[i]=i;
sum[i]=sum[i-]+val[i];
}
for(int i=;i<=n;i++)
for(;l[i]>&&val[l[i]-]>=val[i];)
l[i]=l[l[i]-];
for(int i=n-;i>=;i--)
for(;r[i]<n&&val[r[i]+]>=val[i];)
r[i]=r[r[i]+];
for(int i=;i<=n;i++)
{
LL tmp=val[i]*(sum[r[i]]-sum[l[i]-]);
if(tmp>ans_val)
{
ans_l=l[i];
ans_r=r[i];
ans_val=tmp;
}
}
printf("%I64d\n%d %d",ans_val,ans_l,ans_r);
return ;
}

POJ——T 2796 Feel Good的更多相关文章

  1. 【POJ】2796:Feel Good【单调栈】

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 18449   Accepted: 5125 Case T ...

  2. [poj 2796]单调栈

    题目链接:http://poj.org/problem?id=2796 单调栈可以O(n)得到以每个位置为最小值,向左右最多扩展到哪里. #include<cstdio> #include ...

  3. POJ 2796:Feel Good(单调栈)

    http://poj.org/problem?id=2796 题意:给出n个数,问一个区间里面最小的元素*这个区间元素的和的最大值是多少. 思路:只想到了O(n^2)的做法. 参考了http://ww ...

  4. POJ 2796 Feel Good 【单调栈】

    传送门:http://poj.org/problem?id=2796 题意:给你一串数字,需要你求出(某个子区间乘以这段区间中的最小值)所得到的最大值 例子: 6 3 1 6 4 5 2 当L=3,R ...

  5. POJ 2796[UVA 1619] Feel Good

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16786   Accepted: 4627 Case T ...

  6. poj 2796 Feel Good单调栈

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20408   Accepted: 5632 Case T ...

  7. POJ 2796 / UVA 1619 Feel Good 扫描法

    Feel Good   Description Bill is developing a new mathematical theory for human emotions. His recent ...

  8. Poj 2796 单调栈

    关于单调栈的性质,和单调队列基本相同,只不过单调栈只使用数组的尾部, 类似于栈. Accepted Code: /******************************************* ...

  9. POJ 2796 Feel Good(单调栈)

    传送门 Description Bill is developing a new mathematical theory for human emotions. His recent investig ...

随机推荐

  1. SQL替换制表、回车、换行符和首尾空格

    SQL替换制表.回车.换行符和首尾空格 最近在批量修复数据的时候,需要利用excel导入大量数据.客户提供的数据是没有规范的,大部分数据行都有制表符.回车符.换货符,以及我需要将数据进行首位去重. 目 ...

  2. zabbix4.0 使用nginx前端安装

    注:环境需求:centos7 1.安装阿里云yum源: rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/4.1/rhel/7/x86_64/zabb ...

  3. golang实现php里的serialize()和unserialize()序列和反序列方法

    Golang 实现 PHP里的 serialize() . unserialize() 安装 go get -u github.com/techleeone/gophp/serialize 用法 pa ...

  4. 全面解读Java中的枚举类型enum的使用

    这篇文章主要介绍了Java中的枚举类型enum的使用,开始之前先讲解了枚举的用处,然后还举了枚举在操作数据库时的实例,需要的朋友可以参考下 关于枚举 大多数地方写的枚举都是给一个枚举然后例子就开始sw ...

  5. LVDS原理及设计指南

    LVDS是一种低摆幅的差分信号技术,它使得信号能在差分PCB 线对或平衡电缆上以 几百Mbps的速率传输,其低压幅和低电流驱动输出实现了低噪声和低功耗.       IEEE 在两个标准中对LVDS ...

  6. git帮助命令

    git帮助命令 零.自己实例 cd D://software/code/PHP/phpStudy/PHPTutorial/WWW/github/m_Orchestrate git checkout - ...

  7. “DNS隧道”盗号木马分析——类似hjack偷密码然后利用dns tunnel直传数据发送出去

    摘自:http://www.freebuf.com/articles/network/38276.html# 运行后不断监控顶端窗口,一旦发现为QQ,就弹出一个自己伪造的QQ登陆窗口,诱导用户输入密码 ...

  8. Important Abstractions and Data Structures

    For Developers‎ > ‎Coding Style‎ > ‎ Important Abstractions and Data Structures 目录 1 TaskRunne ...

  9. Debian9.5 配置x11vnc远程桌面

    x11vnc是一个VNC服务器,它允许用户远程查看并用任何VNC查看器与真实的X显示器(即与物理监视器,键盘和鼠标相对应的显示器)进行交互.虽然它的原作者Karl Runge不再开发,但LibVNC和 ...

  10. 兼容IE浏览器的canvas画线和圆圈

    1.新建test.html文件,代码如下: <!DOCTYPE html><html><head>    <meta charset="utf-8& ...