伪100,求调
查看原帖
伪100,求调
701767
qiutian120529楼主2025/1/13 15:45
#include<bits/stdc++.h>
using ll = long long;
using namespace std;

const ll N = 1e5 + 10;
ll n, a[N], ans, cnt, t, pl[N], pr[N], b[N];
stack<ll> st1, st2;

int main(){
  //freopen("b.in", "r", stdin);
  cin >> n;
  for(ll i = 1; i <= n; i++){
    cin >> a[i];
    b[i] = b[i - 1] + a[i];
  }
  for(ll i = 1; i <= n; i++){
    while(!st1.empty() && a[st1.top()] > a[i]){
      pr[st1.top()] = i - 1;
      st1.pop();
    }
    st1.push(i);
  }
  while(!st1.empty()){
    pr[st1.top()] = n + 1;
    st1.pop();
  }
  for(ll i = n; i >= 1; i--){
    while(!st2.empty() && a[st2.top()] > a[i]){
      pl[st2.top()] = i + 1;
      st2.pop();
    }
    st2.push(i);
  }
  while(!st2.empty()){
    pl[st2.top()] = 0;
    st2.pop();
  }
  for(ll i = 1; i <= n; i++){
    //cout << i << ":" << pl[i] << " " << pr[i] << "->" << (b[pr[i]] - b[pl[i] - 1]) << "\n";
    ans = max(ans, (b[pr[i]] - b[pl[i] - 1]) * a[i]);
  }
  cout << ans;
  return 0;
}


2025/1/13 15:45
加载中...