fork download
  1. #include<bits/stdc++.h>
  2. #define f1(i, n) for(ll i=1;i<=n;++i)
  3. #define f0(i, n) for(ll i=0;i<n;++i)
  4. #define ull unsigned long long
  5. #define ll long long
  6. #define rev(a) reverse(a.begin(),a.end())
  7. #define all(x) x.begin(),x.end()
  8. #define so(A, n) sort(A+1, A+n+1)
  9. using namespace std;
  10. const int maxn = 2e5 + 1;
  11. ll A[maxn], B[maxn];
  12. int main()
  13. {
  14. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  15. int n;
  16. cin >> n;
  17. f1(i, n) {
  18. cin >> A[i];
  19. }
  20. int i = 1, j = 1;
  21. ll sum = 0, res = LLONG_MIN;
  22. while (j <= n) {
  23. if (A[j] % 3 != 0) {
  24. sum += A[j];
  25. res = max(res, sum);
  26. ++j;
  27. }
  28. else if (A[j] % 3 == 0 || sum < 0) {
  29. ++j;
  30. i = j;
  31. sum = 0;
  32. }
  33. }
  34. cout << res;
  35.  
  36. return 0;
  37. }
  38.  
  39.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
-9223372036854775808