day3
作者:
__492
,
2024-05-30 21:43:50
,
所有人可见
,
阅读 1
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+9;
int n,tt;
int a[N], s[N], l[N], r[N];
long long sum[N],ans;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
for (int i = 1; i <= n; i++)
{
while (tt && a[s[tt]] >= a[i]) tt--;
l[i] = s[tt];
s[++tt] = i;
}
tt = 0; s[0] = n + 1;
for (int i = n; i >= 1; i--)
{
while (tt && a[s[tt]] >= a[i]) tt--;
r[i] = s[tt] - 1;
s[++tt] = i;
}
for (int i = 1; i <= n; i++) ans = max(ans, (sum[r[i]] - sum[l[i]]) * a[i]);
cout << ans;
return 0;
}