C++ DP O(N*maxval) SPACE COMPLEXITY (O(maxval))
IntuitionApproachComplexity

Time complexity:
O(N*maxval)


Space complexity:
O(maxval)

Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(N*maxval)

- Space complexity:
O(maxval)

# Code
```cpp []
class Solution {
public:
    const int MOD=1e9+7;
    int countOfPairs(vector<int>& nums) {
        int m=*max_element(nums.begin(),nums.end());
        vector<int> dp(m+1,0);
        for (int i=0;i<=nums[0];i++){
            dp[i]=i+1;
        }
        
        for (int i=1;i<nums.size();i++){
            int res=0;
            vector<int> temp=dp;
            for (int j=0;j<=nums[i];j++){
                int upper=min(nums[i-1]-(nums[i]-j),j);
                if (upper>=0){
                    res=(1LL*res+dp[upper])%MOD;
                }
                temp[j]=res;
            }
            dp=temp;
        }
        return dp[nums.back()];
    }
};
```
['C++']