Feel Good
 

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

题意:

  给你n个数,让你找到一个区间l,r使得(a[l] + a[l+1] + ......... + a[r-1]+a[r]) *min{a[l].....a[r]} 的值最大

题解:

  我们预处理出对于每个i位置,以他为最小值时 向左向右能延伸的最远位值

  答案就是扫一遍了,看看以哪个位置为最小的答案最大

  在POJ上交比较好

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
const int N = 1e5+, M = , mod = , inf = 1e9+; typedef long long ll;
const ll mm = 1e14;
int n;
ll a[N],l[N],r[N];
ll sum[N];
int main() {
int T = ;
while(scanf("%d",&n)!=EOF) {
if(T) cout<<endl; T++;
sum[] = ;
ll mi = mm;
for(int i=;i<=n;i++) scanf("%lld",&a[i]) ,sum[i] = sum[i-] + a[i] ,mi = min(mi,a[i]);
l[] = ;a[] = -;a[n+] = -;
for(int i=;i<=n;i++) {
int tmp = i-;
while(a[i]<=a[tmp]) tmp = l[tmp]-;
l[i] = tmp+;
}
r[n] = n;
for(int i=n-;i>=;i--) {
int tmp = i+;
while(a[i]<=a[tmp]) tmp = r[tmp] + ;
r[i] = tmp - ;
}
ll L = ,R = n;
ll mx = sum[n]*mi;
for(int i=;i<=n;i++) {
ll now = (sum[r[i]] - sum[l[i]-])*1ll*a[i];
if(now>mx) {
L = l[i]; R = r[i];
mx = now;
}
}
printf("%lld\n",mx);
printf("%lld %lld\n",L,R);
} return ;
}

POJ 2796 / UVA 1619 Feel Good 扫描法的更多相关文章

  1. POJ 2796[UVA 1619] Feel Good

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

  2. POJ 3525/UVA 1396 Most Distant Point from the Sea(二分+半平面交)

    Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...

  3. uva 1619 - Feel Good || poj 2796 单调栈

    1619 - Feel Good Time limit: 3.000 seconds   Bill is developing a new mathematical theory for human ...

  4. UVA 1619 Feel Good 感觉不错 (扫描法)

    Feel Good Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Bill is deve ...

  5. UVA - 1619 Feel Good(扫描法)

    题目: 思路: 预处理出a[i]在哪个范围区间内是最小的,然后直接遍历a数组求答案就可以了. 这个预处理的技巧巧妙的用了之前的处理结果.(大佬tql) 代码: #include <bits/st ...

  6. UVA 1619 Feel Good(DP)

    Bill is developing a new mathematical theory for human emotions. His recent investigations are dedic ...

  7. POJ 1002 UVA 755 487--3279 电话排序 简单但不容易的水题

    题意:给你许多串字符串,从中提取电话号码,输出出现复数次的电话号码及次数. 以下是我艰难的AC历程:(这题估计是我刷的题目题解次数排前的了...) 题目不是很难理解,刚开始想到用map,但stl的ma ...

  8. [poj 2796]单调栈

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

  9. POJ 1011 / UVA 307 Sticks

    中文题 (一般都比较坑) 思路:DFS (感谢学长的幻灯片) 这破题把我折腾惨了!!!搞了n天 // by Sirius_Ren #include <cstdio> #include &l ...

随机推荐

  1. Gym-100935I Farm 计算几何 圆和矩形面积交

    题面 题意:就是给你一个圆,和你一个矩形,求面积并,且 保证是一种情况:三角剖分后 一个点在圆内 两个在圆外 题解:可以直接上圆与凸多边形交的板子,也可以由这题实际情况,面积等于扇形减两个三角形 #i ...

  2. BZOJ 4259 FFT

    思路: 为什么好多字符串的题都可以用FFT啊.... 我们其实是要判断$\Sigma (a[i]-b[i])^2*a[i]*b[i]==0$ 那就把a串翻转过来 把 上式展开 大力做几遍FFT就好啦~ ...

  3. c语言open()介绍

    2013-09-0914:40:13 1. 头文件: #include <sys/types.h> #include <sys/stat.h> #include <fcn ...

  4. 介绍一个简单的Parser

    我们已经学习了怎样创建一个简单的Monad, MaybeMonad, 并且知道了它如何通过在 Bind函数里封装处理空值的逻辑来移除样板式代码. 正如之前所说的,我们可以在Bind函数中封装更复杂的逻 ...

  5. webpack-1

    1.webpack 安装新项目npm install --save-dev webpack如果版本较老,在package,json中找到版本号,修改成你要的版本号,在删除node-model文件夹,执 ...

  6. Python:Matplotlib 画曲线和柱状图(Code)

    原文链接:http://blog.csdn.net/ikerpeng/article/details/20523679 参考资料:http://matplotlib.org/gallery.html ...

  7. eeee

    Math Behind Rx https://github.com/ReactiveX/RxSwift/blob/master/Documentation/MathBehindRx.md Gettin ...

  8. 如何快速在命令提示符(cmd)中打开指定的文件夹路径!

    按住shift键然后 右击,如图:

  9. apiCloud组件:swiper

    一.apicloud中基于swiper封装了一个模块供调用.就是swiper.js 页面引入js就行 <script type="text/javascript" src=& ...

  10. 克隆CentOS 6.9 配置静态IP,重启网络服务时报错

    克隆的CentOS 6.9 第一次开机时,VMware workstation会为新虚拟机自动生成新mac地址,导致虚拟机配置文件中mac地址与虚拟机新mac地址不一致. 解决方法:1. 修改网卡配置 ...