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. Automake使用(中级)

    工程地址 automake语言国际化 最初工程目录结构 $ ls -l total 16 drwxrwxr-x. 2 fedora fedora 4096 May 10 10:38 build-aux ...

  2. yii2之目录解析

    /backend 1.assets\AppAsset.php2.config\main-local.php 注释14到17行3.controllers\SiteController -> act ...

  3. SAS批量导出sas7bdata至excel

    /*创建输出excel的宏*/ %macro export(inlib,intbl,outpath,outfile); proc export data=&inlib..&intbl ...

  4. js获取当前地址栏的域名、Url、相对路径和参数以及指定参数

    以下代码整理于网络 1.设置或获取对象指定的文件名或路径. window.location.pathname 例:http://localhost:8086/topic/index?topicId=3 ...

  5. Django配置文件解释

    """Django settings for first project. Generated by 'django-admin startproject' using ...

  6. Luogu P1955 [NOI2015]程序自动分析

    又一次做了这道题,感慨万千. 记得寒假时,被cmd2001点起来讲这道题,胡言乱语..受尽鄙视(现在也是好吗)..后来下课想A掉,可是3天下来总是错...后来抄了分题解就咕咕了... 今天老师留了这道 ...

  7. Codeforces 185D(发现性质、欧拉定理)

    学到的东西 不知道gcd时不妨先假设为d,然后为了满足全部式子说不定可以得到d的取值范围. 幂上带幂考虑欧拉定理的使用. 有几个特殊情况会破坏公式的完美不要紧,看看特殊情况是否能简便地判定. 连乘公式 ...

  8. 引擎基本服务接口API介绍

    Slickflow.NET 开源工作流引擎基础介绍(一) -- 引擎基本服务接口API介绍 https://www.cnblogs.com/slickflow/p/4807227.html 工作流术语 ...

  9. 安装Jaspersoft Studio

    下载位置:http://community.jaspersoft.com/project/jaspersoft-studio/releases.

  10. python 7 dict和set

    dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例子,假设要根据同学的名字 ...