7 条题解
-
-4
#include<stdio.h> #include<string.h> #include using namespace std; typedef long long ll; const int N = 1e5 + 5; ll l[N], r[N]; ll a[N]; int n; stack s; int main(){ while(scanf("%d",&n) && n){ while(!s.empty()) s.pop(); for(int i=1; i<=n; ++i){ scanf("%lld",&a[i]); l[i] = r[i] = i; } a[0] = a[n+1] = -1;
for(int i=1; i<=n; ++i){ while(!s.empty() && a[i] <= a[s.top()]) s.pop(); if(s.empty()) l[i] = 0; else l[i] = s.top(); s.push(i); } while(!s.empty()) s.pop(); for(int i=n; i>=1; --i){ while(!s.empty() && a[i] <= a[s.top()]) s.pop(); if(s.empty()) r[i] = n+1; else r[i] = s.top(); s.push(i); } ll sum, max = -1; for(int i=1; i<=n; ++i){ sum = (r[i] - l[i] - 1) * a[i]; if(sum > max) max = sum; } printf("%lld\n",max); } return 0;
}
信息
- ID
- 42
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 5
- 标签
- 递交数
- 221
- 已通过
- 89
- 上传者