12345678910111213141516171819 |
- #include <iostream>
- #include <vector>
- #include <climits>
- int main() {
- std::vector<int> arr = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
- int maxSum = INT_MIN;
- int currentSum = 0;
- for (int num : arr) {
- currentSum = std::max(num, currentSum + num);
- maxSum = std::max(maxSum, currentSum);
- }
- std::cout << maxSum;
- return 0;
- }
|