Feel Good
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 12409   Accepted: 3484
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

 
题意: 给你n个数,求得 max(某个区间和*区间最小值)
 
题解:此代码只能通过poj测评 .... 坑啊
         求得以a[i]为最小值的区间的左界与右界  维护一个单调栈  代码中的*****
这个叫 滑窗算法?
滑动窗口的精髓是在一个数列里保存着一个递增数列,同时这个数列维持了它在原数列的位次递增,这个窗口里保存的第一个数即在这个区间里最小的数。这样不停得把新输入的数同这个滑动窗口里右边的数比较,如果比它大,删除窗口里的这个数,同时删除的数统治区域的最右边就是新输入的数,它的左统治区域即新输入的数的左统治区域,然后不停地向窗口的左边比。这样只需要一个数组记录它左边区域的边界就可以了,  右边同理..
 #include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std;
ll n;
ll a[];
ll sum[];
ll l[],r[];
ll ans;
int gg;
int main()
{
gg=;
while(scanf("%lld",&n)!=EOF)
{
if(gg)
cout<<endl;
gg++;
sum[]=;
ans=-;
int flag=;
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
sum[i]=sum[i-]+a[i];
}
a[]=-;a[n+]=-;
l[]=;
for(int i=;i<=n;i++)//关键********
{
int temp=i-;
while(a[temp]>=a[i])//维护一个递增的序列
temp=l[temp]-;
l[i]=temp+;
}
r[n]=n;
for (int i=n-;i>=;i--)
{
int temp=i+;
while(a[temp]>=a[i])
temp=r[temp]+;
r[i]=temp-;
}
for(int i=;i<=n;i++)
{
ll ggg=(sum[r[i]]-sum[l[i]-])*a[i];
if(ggg>ans)
flag=i;
ans=max(ans,ggg);
}
printf("%lld\n",ans);
printf("%lld %lld\n",l[flag],r[flag]);
}
return ;
}

最新文章

  1. ecshop登录
  2. clock gating and PLL
  3. Android之SQLite
  4. JSP实现数据库(MySQL)查询——Java Web练习(二)
  5. find job
  6. 如何用Excel直接查询Oracle中的数据(转)
  7. SQL server 数据库——数学函数、字符串函数、转换函数、时间日期函数
  8. 事务的四大特性(ACID):
  9. Oracle synonym 同义词
  10. zookeeper部署
  11. 自学Linux Shell11.5-执行数字运算
  12. 42.PHP--电商网站的询价插件
  13. EMIF接口与FPGA的互联(转)
  14. day04_雷神_函数
  15. CF700E:Cool Slogans(SAM,线段树合并)
  16. Ubuntu OpenJDK + Tomcat7 的安装
  17. 保卫萝卜官方PC版——含绿色版 V1.0.6Beta
  18. hdu 4240在(最大流)
  19. 浅谈boost.variant的几种访问方式
  20. Redis之Hash数据结构

热门文章

  1. Jmeter命令行参数
  2. SpringMVC URL模板模式映射
  3. 项目实战2.3-Nginx的“远方表哥”—Tengine
  4. php 获取 今天、昨天、这周、上周、这月、上月、近30天
  5. vue.js 服务端渲染nuxt.js反向代理nginx部署
  6. JZOJ 5455. 【NOIP2017提高A组冲刺11.6】拆网线
  7. vue之神奇的动态按钮
  8. Installing Apps Kattis - installingapps (贪心 + 背包)
  9. 安装ANSYS19.0的正确方法(附下载)
  10. HDU 3966 Aragorn&#39;s Story 树链拋分