Alex_tz307

Fundamente XI - 3 / 218

Sep 21st, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(nullptr);
  8.     cout.tie(nullptr);
  9.     int N;
  10.     cin >> N;
  11.     vector < int > a(N);
  12.     for(int& x : a)
  13.         cin >> x;
  14.     vector < vector < int > > dp(N, vector < int >(2));
  15.     dp[0][1] = a[0];
  16.     for(int i = 1; i < N; ++i) {
  17.         dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
  18.         dp[i][1] = dp[i - 1][0] + a[i];
  19.     }
  20.     cout << max(dp[N - 1][0], dp[N - 1][1]);
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment