Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- typedef long long LL;
- const int maxn=3e5+2;
- int n,m,k;
- LL ans=0;
- int a[maxn];
- LL dp[maxn][10];
- void DP(){
- for (int i=n;i;i--)
- for (int j=0;j<m;j++){
- if (j) dp[i][j]=max(0LL,a[i]+dp[i+1][(j+1)%m]);
- else dp[i][j]=max(0LL,dp[i+1][(j+1)%m]+a[i]-k);
- ans=max(ans,dp[i][0]);
- }
- }
- int main(){
- scanf("%d%d%d%",&n,&m,&k);
- for (int i=1;i<=n;i++) scanf("%d",&a[i]);
- DP();
- printf("%I64d",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement