Advertisement
dudu2004

codeforces 1197D Yet Another Subarray Problem

Jul 22nd, 2019
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. typedef long long LL;
  5. const int maxn=3e5+2;
  6. int n,m,k;
  7. LL ans=0;
  8. int a[maxn];
  9. LL dp[maxn][10];
  10. void DP(){
  11.     for (int i=n;i;i--)
  12.         for (int j=0;j<m;j++){
  13.             if (j) dp[i][j]=max(0LL,a[i]+dp[i+1][(j+1)%m]);
  14.             else dp[i][j]=max(0LL,dp[i+1][(j+1)%m]+a[i]-k);
  15.             ans=max(ans,dp[i][0]);
  16.         }
  17. }
  18. int main(){
  19.     scanf("%d%d%d%",&n,&m,&k);
  20.     for (int i=1;i<=n;i++) scanf("%d",&a[i]);
  21.     DP();
  22.     printf("%I64d",ans);
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement