fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4.  
  5. using namespace std;
  6.  
  7. struct Max
  8. {
  9. int& operator*() { return cur; }
  10. void operator++(){ cur = mx = max(mx,mxe = max(0,mxe+cur)); }
  11. private:
  12. int cur, mx = 0, mxe = 0;
  13. };
  14.  
  15. int main()
  16. {
  17. size_t n;
  18. cin >> n;
  19. cout << *copy_n(istream_iterator<int>(cin),n,Max{});
  20.  
  21. }
  22.  
Success #stdin #stdout 0.01s 5656KB
stdin
8  -1 3 -2 5 3 -5 2 2
stdout
9