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