Advertisement
anon20016

D

Nov 18th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8. #include <algorithm>
  9.  
  10. #define ull unsigned long long
  11. #define ll long long
  12.  
  13. using namespace std;
  14.  
  15. ll d[101];
  16. ll a[101];
  17.  
  18. int main() {
  19. //freopen("input.txt", "r", stdin);
  20. //freopen("output.txt", "w", stdout);
  21. int n;
  22. cin >> n;
  23.  
  24. for (int i = 1; i <= n; i++) {
  25. cin >> a[i];
  26. d[i] = 0;
  27. }
  28. d[0] = 0;
  29. d[1] = a[1];
  30. for (int i = 2; i <= n; i++) {
  31. d[i] = a[i] + max(d[i - 1], d[i - 2]);
  32. }
  33. cout << d[n];
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement