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 - the number of days of Bill's life he is planning to investigate (1n100000) .
The rest of the file contains n integer numbers a1a2,..., an ranging from 0 to 106 - 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 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 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

题意:选取连续的几天,求区间中最小的值*区间值的和的最大值:

ps:大家去POJ交吧。UVA这道题坑死人
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
typedef long long LL;
using namespace std;
const int maxn=1000010;
int l[maxn],r[maxn];
LL sum[maxn],dp[maxn];
int main()
{
int n;
int cas=0;
while(~scanf("%d",&n))
{
memset(sum,0,sizeof(sum));
if(cas)
puts("");
cas++;
for(int i=1;i<=n;i++)
{
scanf("%lld",&dp[i]);
sum[i]=sum[i-1]+dp[i];
l[i]=r[i]=i;
}
// cout<<"23333 "<<endl;
for(int i=1;i<=n;i++)
{
if(dp[i]>0)
{
while(dp[l[i]-1]>=dp[i])
l[i]=l[l[i]-1];
}
}
// cout<<"hahahah "<<endl;
for(int i=n;i>=1;i--)
{
if(dp[i]>0)
{
while(dp[r[i]+1]>=dp[i])
r[i]=r[r[i]+1];
}
}
// cout<<"111 "<<endl;
LL ans=0,temp;
int ll=1,rr=1;
for(int i=1;i<=n;i++)
{
// cout<<"fuck "<<endl;
if(dp[i]>0)
{
temp=dp[i]*(sum[r[i]]-sum[l[i]-1]);
if(temp>ans)
{
ans=temp;
ll=l[i];
rr=r[i];
}
else if(temp==ans)
{
if(rr-ll==r[i]-l[i]&&l[i]<ll)
{
ll=l[i];
rr=r[i];
}
}
}
}
printf("%lld\n%d %d\n",ans,ll,rr);
}
return 0;
}

UVA 1619 Feel Good(DP)的更多相关文章

  1. uva 116 Unidirectional TSP (DP)

    uva 116 Unidirectional TSP Background Problems that require minimum paths through some domain appear ...

  2. UVa 103 - Stacking Boxes(dp求解)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  3. UVA 674 Coin Change(dp)

    UVA 674  Coin Change  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...

  4. POJ1015 && UVA - 323 ~Jury Compromise(dp路径)

    In Frobnia, a far-away country, the verdicts in court trials are determined by a jury consisting of ...

  5. UVa 12186 Another Crisis (DP)

    题意:有一个老板和n个员工,除了老板每个员工都有唯一的上司,老板编号为0,员工们为1-n,工人(没有下属的员工),要交一份请愿书, 但是不能跨级,当一个不是工人的员工接受到直系下属不少于T%的签字时, ...

  6. 【UVa】Palindromic Subsequence(dp+字典序)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=465&page=s ...

  7. UVa 1638 - Pole Arrangement(dp)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVA 1638 Pole Arrangement (dp)

    题意:有n个长度为1到n的柱子排列在一起,从左边看有l根从右边看有r根,问你所以排列中满足这种情况的方案数 题解:就是一个dp问题,关键是下标放什么,值代表什么 使用三维dp,dp[i][j][k]= ...

  9. UVA 11137 Ingenuous Cubrency(dp)

    Ingenuous Cubrency 又是dp问题,我又想了2 30分钟,一点思路也没有,最后又是看的题解,哎,为什么我做dp的题这么烂啊! [题目链接]Ingenuous Cubrency [题目类 ...

随机推荐

  1. HDU OJ 5441 Travel 2015online E

    题目:click here 题意: 有个很暴躁的人,想坐车旅行n个城市.连接城市共有m条路(双向).他坐在车上很不爽,每次最多忍耐x分钟.但是每站下车他又可以休息(重新计时).总共有q次询问.问途中有 ...

  2. Ajax学习之小结

    ajax: * 同步交互和异步交互:  * 同步交互:客户端发送请求——>等待服务器端处理——>接收响应,这个过程客户端不能做任何其他事情,这种模式叫做同步交互  * 异步交互:客户端发送 ...

  3. Sqoop mysql 数据导入到hdfs

    1.--direct 模式使用mysqldump 工具,所以节点上需要安装该工具,非direct 模式直接使用jdbc ,所以不需要 具体script参考如下: sqoop import --conn ...

  4. 初识python yield

    for sel in response.xpath('//ul/li'): item = DmozItem() item['title'] = sel.xpath('a/text()').extrac ...

  5. Java Socket 入门1

    由程序逻辑可以看到 这是一个 客户端和服务端一对一聊天的程序  首先由服务端说第一句话然后对话才开始 且只能客户端一行话  服务端再一行话 这样往复进行  客户端若想不等服务端回应继续说话是不行的 服 ...

  6. win7 资源管理器的背景色修改

    主要参考 http://blog.sina.com.cn/s/blog_49c182c20100w3nb.html win7 通过dll修改背景色首先找到这个文件C:\Windows\Resource ...

  7. 帝国cms7.0调用出栏目下的东西

    打开帝国后台,新建一个栏目,简历一个封面模板为 abc,套用一个封面栏目. [e:loop={"select * from {$dbtbpre}enewsclass where classi ...

  8. QWidget QMainWindow QDialog 之间的区别

    QWidget类是所有用户界面对象的基类. 窗口部件是用户界面的一个原子:它从窗口系统接收鼠标.键盘和其它事件,并且在屏幕上绘制自己的表现.每一个窗口部件都是矩形,并且它们按Z轴顺序排列的.一个窗口部 ...

  9. OC学习那些事:点语法

    1.使用自定义的方法创建get/set方法 Person.h文件: #import <Foundation/Foundation.h> @interface Person : NSObje ...

  10. 【SqlServer数据类型、C#数据类型、SqlDbType】对应关系及转换

    // sql server数据类型(如:varchar)// 转换为SqlDbType类型public static SqlDbType SqlTypeString2SqlType(string sq ...