Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int N;
- cin >> N;
- vector < int > a(N);
- for(int& x : a)
- cin >> x;
- vector < vector < int > > dp(N, vector < int >(2));
- dp[0][1] = a[0];
- for(int i = 1; i < N; ++i) {
- dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
- dp[i][1] = dp[i - 1][0] + a[i];
- }
- cout << max(dp[N - 1][0], dp[N - 1][1]);
- }
Advertisement
Add Comment
Please, Sign In to add comment