找以某个数为最小值的区间
#include <iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
typedef pair< LL,LL > pii;
const LL maxn = 100000 + 100;
pii st[maxn];
LL top,n,a[maxn],sum[maxn],l[maxn],r[maxn];
void solve(){
top = 0;
for( LL i = 1;i <= n;i++ ){
pii cur;
cur.first = i;
cur.second = i;
for( ;top > 0 && a[ st[top-1].first ] >= a[i];top-- ){
cur.second = st[top-1].second;
r[ st[top-1].first ] = a[i] == a[st[top-1].first] ? i : i-1;
}
st[top++] = cur;
l[ i ] = cur.second;
}
}
int main()
{
scanf("%lld",&n);
for( LL i = 1; i <= n;i++ ){
scanf("%lld",&a[i]);
l[i] = r[i] = i;
}
solve();
for( LL i = 0;i < top;i++ ){
r[ st[i].first ] = st[top-1].first;
}
LL ans = -1;
LL ansl,ansr;
sum[0] = 0;
for( LL i = 1;i <= n;i++ ){
sum[i] = sum[i-1] + a[i];
}
for( LL i = 1;i <= n;i++ ){
LL re = a[i] * (sum[ r[i] ] - sum[ l[i]-1 ]);
if( re > ans ){
ans = re;
ansl = l[i];
ansr = r[i];
}
}
printf("%lld\n",ans);
printf("%lld %lld\n",ansl,ansr);
return 0;
}