Feel Good
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 8753   Accepted: 2367
Case Time Limit: 1000MS   Special Judge

Description

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

The first line of the input 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.

Output

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

Source

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top

 /*
题意:10^5个数字,求max { 区间[ ] * 该区间最小值 };
解决思路:
找区间最小值,如果能够求出其长度,那么就可以扫一遍解决。
关键在于找区间最小值。
而且存在一种情况,同一个值,会是许多区间的最小值。
所以,转化一下,求每一个i为最小值的时候,能到到达的最远位置。 */ #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; int a[],b[];
__int64 s[];
int L[],R[];
typedef struct
{
int num;
int rp;
}Queue;
Queue q[],tmp; int main()
{
int n,i;
int head,tail,Num,l,r,lx,rx;
__int64 hxl,tom;
while(scanf("%d",&n)>)
{
for(i=,s[]=;i<=n;i++)
{
scanf("%d",&a[i]);
b[n-i+]=a[i];
s[i]=s[i-]+a[i];
}
memset(L,-,sizeof(L));
memset(R,-,sizeof(R));
head=;tail=-;
for(i=;i<=n;i++)
{
tmp.num=i;
tmp.rp=a[i];
while( head<=tail && q[tail].rp>tmp.rp )
{
if( R[q[tail].num]==-)
{
R[q[tail].num]= i - q[tail].num-;
}
tail--;
}
q[++tail]=tmp;
}
while( head<=tail )
{
Num=q[tail].num-q[head].num;
if( R[q[head].num]==-)
{
R[q[head].num]=Num;
}
head++;
}
head=;tail=-;
for(i=;i<=n;i++)
{
tmp.num=i;
tmp.rp=b[i];
while( head<=tail && q[tail].rp>tmp.rp )
{
Num=n-q[tail].num+;
if( L[Num]==-)
L[Num]= i - q[tail].num-;
tail--;
}
q[++tail]=tmp;
}
while( head<=tail )
{
Num=n-q[head].num+;
if( L[Num]==-)
{
L[Num]=q[tail].num-q[head].num;
}
head++;
}
for(tom=-,i=;i<=n;i++)
{
l=i-L[i];
r=i+R[i];
hxl=(s[r]-s[l-])*a[i];
if( hxl>tom)
{
tom=hxl;
lx=l;
rx=r;
}
}
printf("%I64d\n%d %d\n",tom,lx,rx);
}
return ;
}

poj 2796 Feel Good 单调队列的更多相关文章

  1. POJ 2823 Sliding Window + 单调队列

    一.概念介绍 1. 双端队列 双端队列是一种线性表,是一种特殊的队列,遵守先进先出的原则.双端队列支持以下4种操作: (1)   从队首删除 (2)   从队尾删除 (3)   从队尾插入 (4)   ...

  2. poj 2823 Sliding Window (单调队列入门)

    /***************************************************************** 题目: Sliding Window(poj 2823) 链接: ...

  3. poj 1821 Fence(单调队列优化DP)

    poj 1821 Fence \(solution:\) 这道题因为每一个粉刷的人都有一块"必刷的木板",所以可以预见我们的最终方案里的粉刷匠一定是按其必刷的木板的顺序排列的.这就 ...

  4. POJ 2823 滑动窗口 单调队列模板

    我们从最简单的问题开始: 给定一个长度为N的整数数列a(i),i=0,1,...,N-1和窗长度k. 要求: f(i) = max{a(i-k+1),a(i-k+2),..., a(i)},i = 0 ...

  5. POJ 3709 K-Anonymous Sequence (单调队列优化)

    题意:给定一个不下降数列,一个K,将数列分成若干段,每段的数字个数不小于K,每段的代价是这段内每个数字减去这段中最小数字之和.求一种分法使得总代价最小? 思路:F[i]表示到i的最小代价.f[i]=m ...

  6. POJ 2823 滑动窗口 单调队列

    https://vjudge.net/problem/POJ-2823 中文:https://loj.ac/problem/10175 题目 给一个长度为 $N$ 的数组,一个长为 $K$ 的滑动窗体 ...

  7. POJ 2823 Sliding Window (单调队列)

    单调队列 加了读入挂比不加更慢.... 而且这份代码要交c++ 有大神G++跑了700ms..... orzorzorz #include<iostream> #include<cs ...

  8. poj 3162 树DP+单调队列

    http://acm.hust.edu.cn/vjudge/problem/11552 http://blog.csdn.net/woshi250hua/article/details/7727677 ...

  9. poj 2823 Sliding Windows (单调队列+输入输出挂)

    Sliding Window Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 73426   Accepted: 20849 ...

随机推荐

  1. Apache环境修改.htaccess文件实现子目录强制HTTPS访问

    如果要在Apache环境下实现子目录强制HTTPS地址访问,该怎么实现呢?在此文章中将与大家一起分享如何在Apache环境下修改.htaccess文件来实现子目录强制HTTPS地址访问. 1.根目录域 ...

  2. 树形DP学习笔记

    树形DP 入门模板题 poj P2342 大意就是一群职员之间有上下级关系,每个职员有一个快乐值,但是只有在他的直接上级不在场的情况下才会快乐.求举行一场聚会的快乐值之和的最大值. 求解 声明一个数组 ...

  3. python实现数据库增删改查

    column_dic = {"id": 0, "name": 1, "age": 2, "phone": 3, &quo ...

  4. RocketMQ消息发送的队列选择与容错策略

    一个topic有多个队列,分散在不同的broker.producer在发送消息的时候,需要选择一个队列 producer发送消息全局时序图: 队列选择与容错策略结论: 在不开启容错的情况下,轮询队列进 ...

  5. SpringMVC初写(二)映射类型、限制和数据绑定

    映射路径 a)映射路径的概述 所谓的映射路径,就是匹配请求路径和执行方法关系的路径 请求路径:http://localhost:8080/springmvc-demo-cofig/say.do 映射路 ...

  6. [Xamarin] 產生專案的AndroidManifest.xml (转帖)

    紀錄一下 Xamarin 如何開啟 AndroidManifest.xml,因為這跟權限有關係,每個Android App幾乎都要設定 每次都想Add File 去增加但是其實是不對的 工具上面不管是 ...

  7. 通过System获取java环境变量的路径

    通过System获取java环境变量的路径代码为: import java.io.FileNotFoundException; import java.io.FileOutputStream; imp ...

  8. 之前为dd写的一个小的demo(robotium)

    测试类的编写: package com.m1905.dd.mobile; import com.robotium.solo.By; import com.robotium.solo.Solo; imp ...

  9. java 命令--备忘

    java -Djava.ext.dirs=/tmp/spark-sample/lib/ -cp ./spark-sample-1.0.jar com.sample.StartLauncher

  10. MySQL之mysql命令使用详解

    MySQL Name mysql - the MySQL command-line tool Synopsis mysql [options] db_name Description mysql is ...