Advertisement
LEGEND2004

B - The staircase

Sep 6th, 2023
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. const int N = 1e3 + 5;
  6. const int mod = 1e9 + 7;
  7. const int INF = 1e18;
  8. int a[N];
  9. int dp[N];
  10.  
  11. signed main()
  12. {
  13.     int n , k;
  14.     cin >> n;
  15.     for(int i = 1; i <= n; i++){
  16.         cin >> a[i];
  17.     }
  18.     cin >> k;
  19.     for(int i = 1; i <= (n + 1); i++){
  20.         int m = INT_MIN;
  21.         for(int j = (i - 1); j >= max(i - k , 0ll); j--){
  22.             m = max(m , dp[j]);
  23.         }
  24.         dp[i] = m + a[i];
  25.     }
  26.     cout << dp[n + 1] << endl;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement