task3.cpp 358 B

12345678910111213141516171819
  1. #include <iostream>
  2. #include <vector>
  3. #include <climits>
  4. int main() {
  5. std::vector<int> arr = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
  6. int maxSum = INT_MIN;
  7. int currentSum = 0;
  8. for (int num : arr) {
  9. currentSum = std::max(num, currentSum + num);
  10. maxSum = std::max(maxSum, currentSum);
  11. }
  12. std::cout << maxSum;
  13. return 0;
  14. }