Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, m;
- int a[10001], f[10001][501];
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- freopen("RUN.INP","r",stdin);
- freopen("RUN.OUT","w",stdout);
- cin>>n>>m;
- for(int i=1; i<=n; i++)
- cin>>a[i];
- for(int i=1; i<=n; i++) {
- f[i][0] = f[i-1][0];
- for(int j=i-1,e=1; j>0,e<=m; j--,e++)
- f[i][0] = max(f[i][0], f[j][e]);
- for(int e=1; e<=m; e++)
- f[i][e] = f[i-1][e-1]+a[i];
- }
- cout<<f[n][0];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement