提交时间:2023-08-14 12:29:12
运行 ID: 98221
#include<bits/stdc++.h> using namespace std; #define ll long long #define N 200005 ll sum[N]; ll a[N]; int main(){ int n,k; ll x; scanf("%d%d%lld",&n,&k,&x); if(x<0)x=-x,k=n-k; for(int i=1;i<=n;i++) scanf("%lld",&a[i]),sum[i]=sum[i-1]+a[i]; ll ans=0; for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) ans=max(ans,sum[j]-sum[i-1]+min(j-i+1,k)*x-max(j-i+1-k,0)*x); printf("%lld",ans); return 0; }