Feel Good

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

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 day was. 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 input will contain several test cases, each of them as described below. Consecutive test cases are separated by a single blank line.

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

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

On the first line of the output file print the greatest value of some period of Bill's life.

On the second line print two numbers l<tex2html_verbatim_mark> and r<tex2html_verbatim_mark> such that the period from l<tex2html_verbatim_mark> -th to r<tex2html_verbatim_mark> -th day of Bill's life (inclusive) has the greatest possible value. If there are multiple periods with the greatest possible value, then print the shortest one. If there are still several possibilities, print the one that occurs first..

Sample Input

6
3 1 6 4 5 2

Sample Output

60
3 5

对于某个最小值ai来说,所选的区间应该尽量大,直到再选就不能保证ai是最小值的时候停止。

在扫描过程中维护一个向前延伸的最大位置,扩展的时候注意传递性,如果前面一个元素比它小,那么前面一个元素能延伸到的位置,

当前元素也可以延伸到,然后类似链表往前找的同时延伸链即可。向后找的时候类似。区间和用一个前缀和来处理。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+;
typedef long long ll;
int a[maxn],l[maxn],r[maxn],n;
ll sum[maxn]; int main()
{
int T = ; sum[] = ; a[] = -;
while(~scanf("%d",&n)){
if(T++) putchar('\n');
a[n+] = -;
for(int i = ; i <= n; i++)
scanf("%d",a+i),sum[i] = sum[i-]+a[i],l[i]=r[i]=i; for(int i = ; i <= n; i++){
while(a[i]<=a[l[i]-]) l[i] = l[l[i]-];
} for(int i = n; i >= ; i--){
while(a[i]<=a[r[i]+]) r[i] = r[r[i]+];
}
ll Max = (ll)a[]*a[];
int L = ,R = ;
for(int i = ; i <= n; i++){
ll tmp = (sum[r[i]]-sum[l[i]-])*a[i];
if(tmp > Max || (tmp == Max && R - L > r[i] - l[i] )){
Max = tmp;
L = l[i]; R = r[i];
}
}
printf("%lld\n%d %d\n",Max,L,R);
}
return ;
}

UVA 1619 Feel Good 感觉不错 (扫描法)的更多相关文章

  1. 推荐一些常用感觉不错的jQuery插件

    转:http://www.cnblogs.com/v10258/p/3263939.html JQuery插件繁多,下面是个人在工作和学习中用到感觉不错的,特此记录. UI: jquery UI(官方 ...

  2. 最近发现docker感觉不错

    最近发现docker感觉不错,接下来开始学习docker方面的技术.lxc也可以学学. storm,kafka也要熟悉起来.

  3. 逛csdn看见的一个知识阶梯,感觉不错

    逛csdn看见的一个知识阶梯,感觉不错: 计算机组成原理 →  DOS命令 → 汇编语言 → C语言(不包括C++).代码书写规范 → 数据结构.编译原理.操作系统 → 计算机网络.数据库原理.正则表 ...

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

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

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

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

  6. 亲测!阿里云公共DNS,感觉不错!

    最近阿里推出了公共DNS,这对于普通的网友来说估计没什么用处,但对于我们建站人来说,确实是一个不错的消息.一听说阿里出公共DNS,博主就立马换电信的DNS换下了.经过这几天的测试,相当满意! 个人感觉 ...

  7. UVA 1619 Feel Good(DP)

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

  8. POJ 2796[UVA 1619] Feel Good

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

  9. 第一次用python,成功的感觉不错。

    自己的作业: 1. count = 0 while count <= 9 : count += 1 if count == 7 : continue print (count) 2. count ...

随机推荐

  1. LeetCode: 669 Trim a Binary Search Tree(easy)

    题目: Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so th ...

  2. 2010辽宁省赛G(佩尔方程)

    #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...

  3. css 实现垂直水平居中常用方法

    html <div class="outer"> <div class="inner"></div> </div> ...

  4. tarjan求强连通分量的思考

    我是按照这里的思路来的.这个博文只是感性理解. 递归树 关于递归树,这篇博文讲的很好,我只是给自己总结一下. 定义vis数组,在dfs连通图时赋予它们不同的含义: vis=0,表示这个点没有被访问. ...

  5. uoj#349. 【WC2018】即时战略(动态点分治)

    传送门 头一次看着题解有一种咱不会\(c++\)的感觉-- 看题解吧-- //minamoto #include<bits/stdc++.h> #include "rts.h&q ...

  6. Sublime Text 3 最新注册码激活码 和 Sublime Text 2 注册码

    Sublime是一款很好用的很轻巧的编辑器,堪称一代神级编辑器.此篇文章用于简单学习记录下神器的激活码,不作其他用途.如有侵权,请联系删除,谢谢~~   1.官方下载地址: http://www.su ...

  7. pgfincore外部OS缓存安装

    su - root cd /opt/soft_baktar -zxvf pgfincore-1.0.gz cd pgfincore-b2b53deexport PATH=/opt/pgsql963/b ...

  8. B.DongDong认亲戚

    链接:https://ac.nowcoder.com/acm/contest/904/B 题意: DongDong每年过春节都要回到老家探亲,然而DongDong记性并不好,没法想起谁是谁的亲戚(定义 ...

  9. 位运算>>和>>>区别

    int a=-1; Integer b=0; Integer c=0; System.out.println(Integer.toBinaryString(a)); b=a>>1; c=a ...

  10. D - Simple String CSU - 1550

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550 很久都没补这题,最近想学网络流,就看看,队友以前用网络流过的,Orz, 但是这题只需要简 ...