对于每座高楼,两侧的楼不能同时高于这座楼
于是就是一个关于高楼的单峰函数
暴力枚举以每个位置作为最高点的答案
注意开 long long
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 100010;
int n;
ll a[maxn],b[maxn],ans[maxn];
ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }
int main(){
n = read();
for(int i=1;i<=n;i++) a[i] = read();
ll ma = 0;
for(int i=1;i<=n;i++){
ll h = a[i],sh = a[i];
b[i] = a[i];
for(int j=i-1;j>=1;j--){
if(a[j] >= h){
b[j] = h;
sh += b[j];
}else{
h = a[j];
b[j] = h;
sh += b[j];
}
}
h = a[i];
for(int j=i+1;j<=n;j++){
if(a[j] >= h){
b[j] = h;
sh += b[j];
}else{
h = a[j];
b[j] = h;
sh += b[j];
}
}
if(sh>ma){
ma = sh;
for(int j=1;j<=n;j++){
ans[j] = b[j];
}
}
}
for(int i=1;i<=n;i++) printf("%lld ",ans[i]); printf("
");
return 0;
}