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. web API请求与参数获取

    总结webAPI的常用请求方法与后台参数的获取: 一:get请求:(会将所以参数拼接到URL里面) 1:基础类型:string  a=“hello” , 前端无论你是写到ajax里面的data属性还是 ...

  2. JS判断上传文件类型

    /*   * 判断图片类型   */    function checkImgType(ths){        if (ths.value == "") {            ...

  3. WPF之触发器

    简单触发器<Window x:Class="WpfApp.Window1" xmlns="http://schemas.microsoft.com/winfx/20 ...

  4. 数据库路由中间件MyCat - 源代码篇(5)

    此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 3. 连接模块 如之前所述,MyCat的连接分为前端和后端,下面是连接基本相关类图: 3.1 Closabl ...

  5. Angular中依赖注入方式的几种写法

    1.第一种写法 angular.module('App').controller('TestCtrl',['$scope', function($scope) {}]); 2.第二种写法 angula ...

  6. chrome调式工具

    1.Elementshttps://segmentfault.com/a/1190000008316690 2. Consolehttps://segmentfault.com/a/119000000 ...

  7. 手机端处理布局rem

    方法一 if (document.documentElement.clientWidth > 600) {//页面宽度大于600px让其宽度等于600px,字体大小等于60px,居中 docum ...

  8. Linux下查看磁盘剩余空间和文件夹大小

    1. du -sh 查看当前文件夹大小 2. du -sh * | sort -n 列出当前文件夹下的所有文件夹及其大小,并按照文件夹大小排序 du - sh *  //查看当前文件夹下所有文件的大小 ...

  9. poj1273 Drainage Ditches (最大流模板)

    http://poj.org/problem?id=1273 Dinic算法 这是一道最大流的经典题 最大流尽量应该用边表,优于邻接矩阵(所以我写了邻接矩阵版的之后又写了个边表) 用了新学的Dinic ...

  10. 【ZJOI2007】捉迷藏 小小的总结

    2019-01-09 22:56:33 终于终于把这道题目做掉了... 做了两个晚上..不知道为什么自己如此之笨.. 在洛谷上断断续续一共交了24次,感觉自己都要被封号了. 昨天花半个晚上从零开始研究 ...