70分(wa三个),求助
查看原帖
70分(wa三个),求助
341864
sgxsz楼主2024/10/23 10:20
#include<bits/stdc++.h>
using namespace std;

inline int read(){
	register int x=0,ch=getchar();
	while(ch<'0'||ch>'9')	ch=getchar();
	while(ch<='9'&&ch>='0'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	return x;
}
#define int long long
int a[100005],st[100005],f[100005],q[100005];

signed main()
{
	//freopen("P2422_9.in","r",stdin);
	register int i,j,n,s,t,x,y,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)	st[i]=st[i-1]+(a[i]=read());
	
	s=1; t=0;
	for(i=1;i<=n;i++){
		while(s<=t&&a[q[t]]>=a[i])	t--;
		q[++t]=i;
		x=a[q[s]]*(st[i]-st[q[s-1]]);
		while(s<t&&x<=a[q[s+1]]*(st[i]-st[q[s]])){
			x=a[q[s+1]]*(st[i]-st[q[s]]); s++;	
		}
		f[i]=x;
		//printf("f[%lld]=%lld q[s]=%lld q[t]%lld\n",i,f[i],q[s],q[t]);
		ans=max(ans,f[i]);
	}
	cout<<ans;
	
	return 0;
}
2024/10/23 10:20
加载中...