fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define dou double
  5. #define pii pair<int,int>
  6. #define pll pair<ll,ll>
  7. #define fi first
  8. #define se second
  9. #define pb push_back
  10. #define FOR(i,a,b) for(int i=(a); i<=(b); i++)
  11. #define FORD(i,a,b) for(int i=(a); i>=(b); i--)
  12. #define REP(i,a,b) for(int i=(a); i<(b); i++)
  13. #define el '\n'
  14. #define all(x) (x).begin(), (x).end()
  15. const int maxN = 2e5;
  16. const int maxM = 3e3;
  17. const int LOG = 20;
  18. const int mod = (int)1e9 + 7;
  19. const ll oo = 1e18;
  20. int n;
  21. ll dp[maxN+5];
  22. int a[maxN+5];
  23. ll ans;
  24.  
  25. int main()
  26. {
  27. ios_base::sync_with_stdio(0); cin.tie(0);
  28. #define task ""
  29. if(fopen(task".inp", "r"))
  30. {
  31. freopen(task".inp", "r", stdin);
  32. freopen(task".out", "w", stdout);
  33. }
  34. cin >> n;
  35. FOR(i,1,n) cin >> a[i];
  36. dp[1] = a[1];
  37. FOR(i,2,n)
  38. {
  39. dp[i] = max(dp[i-1], dp[i-2] + 1LL*a[i]);
  40. ans = max(ans, dp[i]);
  41. }
  42. cout << ans;
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Standard output is empty