1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution { public: int maxAscendingSum(vector<int>& nums) { int n = nums.size(), l = 0, r = 1, ans = INT_MIN; while(r < n){ if(nums[r] > nums[r - 1]){ r++; continue; } int sum = accumulate(nums.begin() + l, nums.begin() + r, 0); ans = max(ans, sum); l = r; r++; } int sum = accumulate(nums.begin() + l, nums.end(), 0); ans = max(ans, sum); return ans; } };
|