# 1800. Maximum Ascending Subarray Sum

Given an array of positive integers `nums`, return the *maximum possible sum of an **ascending** subarray in* `nums`.

```
```

A subarray is defined as a contiguous sequence of numbers in an array.

A subarray `[numsl, numsl+1, ..., numsr-1, numsr]` is **ascending** if for all `i` where `l <= i < r`, `numsi < numsi+1`. Note that a subarray of size `1` is **ascending**.

**Example 1:**

```
Input: nums = [10,20,30,5,10,50]
Output: 65
Explanation: [5,10,50] is the ascending subarray with the maximum sum of 65.
```

**Example 2:**

```
Input: nums = [10,20,30,40,50]
Output: 150
Explanation: [10,20,30,40,50] is the ascending subarray with the maximum sum of 150.
```

思路： DP

1. 由于是连续的subarray每次只要和前面的arr\[i-1]对比看符不符合条件，所以只要一个loop
2. state: 当前第i个element的符合条件arr\[i]>arr\[i-1]的cumulative sum,&#x20;
3. 转移方程是 if arr\[i]>arr\[i-1],  cum-sum += arr\[i]  otherwise,  cum-sum = arr\[i]
4. optimal solution 是当前的最大值

```
class Solution:
    def maxAscendingSum(self, nums: List[int]) -> int:
        #
        #
        #test case:   [10, 20, 30, 5, 10, 50]
        #
        #
        if not nums:
            return None
        cum_sum = max_sum = nums[0]
        for i in range(1, len(nums)):
            if nums[i] > nums[i-1]:
                cum_sum += nums[i]
            else:
                cum_sum = nums[i]
            max_sum = max(max_sum, cum_sum)
        return max_sum
            
        
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wenkangwei.gitbook.io/leetcode-notes/datastructure/dynamicprogramming/untitled.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
