Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n, m;
  5. int a[10001], f[10001][501];
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(0);
  9.     cin.tie(0);
  10.  
  11.     freopen("RUN.INP","r",stdin);
  12.     freopen("RUN.OUT","w",stdout);
  13.  
  14.     cin>>n>>m;
  15.     for(int i=1; i<=n; i++)
  16.         cin>>a[i];
  17.  
  18.     for(int i=1; i<=n; i++) {
  19.         f[i][0] = f[i-1][0];
  20.         for(int j=i-1,e=1; j>0,e<=m; j--,e++)
  21.             f[i][0] = max(f[i][0], f[j][e]);
  22.  
  23.         for(int e=1; e<=m; e++)
  24.             f[i][e] = f[i-1][e-1]+a[i];
  25.     }
  26.  
  27.     cout<<f[n][0];
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement