hopingsteam

Untitled

Apr 7th, 2020
96
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("bac.in");
  7.  
  8. int main()
  9. {
  10. int x, s = 0, smax = 0;
  11. int max = -1000, poz = 0;
  12. while(fin >> x)
  13. {
  14. s = s + x;
  15. if(s < 0)
  16. s = 0;
  17. if(s > smax)
  18. smax = s;
  19. if(x > max)
  20. max = x;
  21. if(x > 0)
  22. poz++;
  23. }
  24. if(poz == 0)
  25. cout << max;
  26. else
  27. cout << smax;
  28. return 0;
  29. }
RAW Paste Data