提交时间:2023-08-14 11:59:00

运行 ID: 98081

#include<bits/stdc++.h> using namespace std; inline int read(){ int x=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } int n,k,x,a[200005],sum[200005],ans; int main(){ n=read(),k=read(),x=read(); for(int i=1;i<=n;i++)a[i]=read(),sum[i]=sum[i-1]+a[i]; if(x<0)k=n-k,x=-x; for(int i=1;i<=n;i++){ for(int j=i;j<=n;j++){ int len=j-i+1; if(k>=len)ans=max(ans,sum[j]-sum[i-1]+len*x); else ans=max(ans,sum[j]-sum[i-1]+(k-len+k)*x); // cout<<i<<" "<<j<<" "<<(k>=len)<<" "<<len*x<<" "<<sum[j]-sum[i-1]<<" "<<ans<<endl; } } cout<<ans<<endl; return 0; }