Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 13376 | Accepted: 3719 | |
Case Time Limit: 1000MS | Special Judge |
Description
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
Output
Sample Input
6
3 1 6 4 5 2
Sample Output
60
3 5
Source
题意:非负整数,求一个区间,区间和*区间最小值 最大
//
// main.cpp
// poj2796
//
// Created by Candy on 10/5/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int N=1e5+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x;
}
int n;
ll a,ans=-,ansb,anse;
struct data{
ll h,l;
int b;
}st[N];
int top=;
int main(int argc, const char * argv[]) {
n=read();
for(int i=;i<=n;i++){
a=read();
ll right=;int b=i;
while(top&&st[top].h>=a){
ll tmp=(st[top].h*(st[top].l+right));
right+=st[top].l;
b=st[top].b;
if(tmp>ans){
ans=tmp;
ansb=st[top].b;
anse=i-;//printf("t %lld %lld %lld\n",ans,ansb,anse);
}
top--;
}
top++;
st[top].h=a;
st[top].l=right+a;
st[top].b=b;
}
ll right=;
while(top){
ll tmp=(st[top].h*(st[top].l+right));
right+=st[top].l;
if(tmp>ans){
ans=tmp;
ansb=st[top].b;
anse=n;
}
top--;
}
printf("%lld\n%lld %lld",ans,ansb,anse);
return ;
}