fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const long long MaxN = 2e5 + 5;
  5. long long n, a[MaxN];
  6.  
  7. void input()
  8. {
  9. cin >> n;
  10. for(long long i = 1; i <= n; i++)
  11. {
  12. cin >> a[i];
  13. }
  14. }
  15.  
  16. void solve()
  17. {
  18. long long cur = a[1];
  19. long long ans = a[1];
  20.  
  21. for(long long i = 2; i <= n; i++)
  22. {
  23. cur = max(a[i], cur + a[i]);
  24. ans = max(ans, cur);
  25. }
  26.  
  27. cout << ans;
  28. }
  29.  
  30. int main()
  31. {
  32. ios_base::sync_with_stdio(0);
  33. cin.tie(0);
  34.  
  35. input();
  36. solve();
  37. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty