Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
98194 CSYZ_HeYC 早凉与序列4 C++ 解答错误 30 13 MS 4396 KB 1187 2023-08-14 12:27:03

Tests(20/24):


#include<bits/stdc++.h> using namespace std; #define ll long long template<typename T>inline void read(T &ret){ ret=0;T fh=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')fh=-1;ch=getchar();} while(isdigit(ch))ret=ret*10+(ch^48),ch=getchar(); ret*=fh; } const int N=2e5+5; ll n,k,x,a[N],sum[N],mx=-2e9,ans; ll q[N],l,r; void solve(){ static ll b[N],aans,ssum; for(int i=1;i<=n-k+1;++i){ for(int j=1;j<=n;++j) if(i<=j&&j<=i+k-1)b[j]=a[j]+x; else b[j]=a[j]-x; for(int bl=1;bl<=n;++bl){ ssum=0; for(int br=bl;br<=n;++br) aans=max(aans,ssum+=b[br]); } } printf("%lld\n",aans); } inline ll work(int i,int j){ return x*min(i-q[j],k)-x*max(0ll,i-q[j]-k); } int main(){ read(n);read(k);read(x); if(x<0)x=-x,k=n-k; for(int i=1;i<=n;++i){ read(a[i]); mx=max(mx,a[i]); sum[i]=sum[i-1]+a[i]; } if(n<=100){solve();return 0;} ans=k?mx+x:mx-x; if(ans<=0)return puts("0"),0; for(int i=1;i<=n;++i){ while(l<r&&sum[l]-work(i,l)>=sum[l+1]-work(i,l+1))++l; ans=max(ans,sum[i]-sum[q[l]]+work(i,l)); while(l<=r&&sum[q[r]]-work(i+1,r)>=sum[i]-(k?x:-x))--r; q[++r]=i; } printf("%lld\n",ans); return 0; }


测评信息: