C++ | Beats 100 % | TC: O(n*max_element) | SC: O(n*max_element)
Code\n\n#define MOD 1000000007\nclass Solution {\npublic:\n    int countOfPairs(vector<int>& arr) {\n        int n = arr.size();\n        int mx = *max_element(
# Code\n```\n#define MOD 1000000007\nclass Solution {\npublic:\n    int countOfPairs(vector<int>& arr) {\n        int n = arr.size();\n        int mx = *max_element(arr.begin(),arr.end());\n        vector<vector<int>>dp(n,vector<int>(mx+1,0));\n\n        for(int i=0;i<=arr[0];i++){\n            dp[0][i] = 1;\n        }\n\n        for(int i=1;i<n;i++){\n            int cnt = 0;\n            int k =0;\n            for(int j=0;j<=arr[i];j++){\n                if(k<=min(j,j-(arr[i]-arr[i-1]))){\n                    cnt = (cnt + dp[i-1][k]) % MOD;\n                    k++;\n                }\n                dp[i][j] = cnt;\n            }\n        }\n\n        int ans = 0;\n        for(int i=0;i<=mx;i++){\n            ans = (ans + dp[n-1][i]) % MOD;\n        }\n        \n        return ans;\n    }\n};\n```\n![temp.png](https://assets.leetcode.com/users/images/05ee467d-f130-4849-8c58-2d0b30c1103f_1723368464.7890213.png)\n\n\n\n
['C++']