fork download
  1. // Author : zvwgvx
  2.  
  3. #pragma GCC optimize("O3,unroll-loops")
  4. #include <bits/stdc++.h>
  5.  
  6. #if LOCAL
  7. #include <algo/debug.h>
  8. #endif
  9.  
  10. using namespace std;
  11. using ll = long long;
  12.  
  13. const int MOD = 1e9 + 7;
  14. const int LIMIT = 1e6 + 7;
  15. const ll INF = LLONG_MAX;
  16.  
  17. signed main() {
  18. cin.tie(nullptr), cout.tie(nullptr) -> ios_base::sync_with_stdio(false);
  19.  
  20. #define task "sol"
  21. if (fopen(task".inp", "r")) {
  22. freopen(task".inp", "r", stdin), freopen(task".out", "w", stdout);
  23. }
  24.  
  25. int n;
  26. cin >> n;
  27.  
  28. vector<ll> arr(n);
  29.  
  30. for (ll& val : arr) cin >> val;
  31.  
  32. ll even = 0, odd = -INF;
  33. ll res = -INF;
  34.  
  35. for (ll val : arr) {
  36. ll n_even, n_odd;
  37.  
  38. if (val & 1) {
  39. n_even = (odd == -INF ? -INF : odd + val);
  40. n_odd = max(val, even + val);
  41. } else {
  42. n_even = max(val, even + val);
  43. n_odd = (odd == -INF ? -INF : odd + val);
  44. }
  45.  
  46. even = n_even;
  47. odd = n_odd;
  48.  
  49. res = max(res, odd);
  50. }
  51.  
  52. cout << res;
  53.  
  54. return 0;
  55. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
-9223372036854775807