用户ID: 密码: 验证:

登 录

注 册 取回密码

中山教育

中山国际网

中国教育在线

时代财富科技公司 FortuneAge Technology Co., Ltd. 校园博客客服网站(新)

我的资料

Mpq

博客信息

积分:988
等级:4级 lv 4
日志总数:231
发表评论总数:18 ( 查看)
获得评论总数:21
发表留言总数:0
所属学校:三鑫
收藏本站:

最新公告

欢迎光临我的博客!

最新相册

我的日历

最新评论

--游客
好文好文,是您的手笔?如果是您的文章,如果您愿意和我联系,...
还有就是数学不能使用计算器…….......在读初中之前原...
--Mpq
这次似乎不举行冬季长跑……看来在三鑫参加的体育项目最终是以...
--Mpq
看了你的"总结", 挺有针对性的! 相信下学期你一定会有...

RSS


首页 -> Zoj题库->Feel Good
Feel Good

Feel Good

Time limit: 10 Seconds   Memory limit: 32768K   Special Judge
Total Submit: 822   Accepted Submit: 181  

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

There are several test cases in the input file. The first line of each case 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. Proceed to the end of file.

Output

For each test case, 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

程序:

program zju_2642_mpq;

const maxn=100001;
var
  n,i,k,start,stops:longint;
  max,tmp:int64;
  sum:array[0..maxn] of int64;
  b:array[0..maxn] of longint;
  a:array[0..maxn] of longint;

begin
  a[0]:=-100;
  while not eof do
  begin
    readln(n);
    a[n+1]:=-100;
    for i:=1 to n do
    begin
      read(a[i]);
      sum[i]:=sum[i-1]+a[i];
    end;
    readln;
    for i:=1 to n do
    begin
      k:=i;
      while a[k-1]>a[i] do k:=b[k-1];
      b[i]:=k;
    end;
    max:=-100;
    for i:=n downto 1 do
    begin
      k:=i;
      while a[k+1]>=a[i] do k:=b[k+1];
      tmp:=(sum[k]-sum[b[i]-1])*a[i];
      if tmp>max then
      begin
        max:=tmp;
        start:=b[i];
        stops:=k;
      end;
      b[i]:=k;
    end;
    writeln(max);
    writeln(start,' ',stops);
  end;
end.

网友评论

共 0 页,0 条记录  

用户名:
密码:
您的评论:
正在载入编辑器...
请输入验证码:


发 表 评 论

Mpq-中山教师家园