NOTICEBOARD | C++ | Beats 100 % Time, 100% memory
\n\n#define ll long long\nclass Solution {\npublic:\n\n    \n    int countOfPairs(vector<int>& nums) {\n        \n        ll MOD = 1000000007;\n        int LIMI
\n```\n#define ll long long\nclass Solution {\npublic:\n\n    \n    int countOfPairs(vector<int>& nums) {\n        \n        ll MOD = 1000000007;\n        int LIMIT = 1001;\n        ll n = nums.size();\n        ll minE = *min_element(nums.begin(),nums.end());\n        \n        \n        vector<ll>minA(n), maxA(n);\n        \n        minA[0] = 0;\n        for(ll i = 1;i<n;i++){\n            if(nums[i]<=nums[i-1])       minA[i] = minA[i-1];\n            else{\n                ll diff = nums[i]-nums[i-1];\n                minA[i] = minA[i-1]+diff;\n                if(minA[i] > nums[i])      return 0;\n            }\n        }\n        \n        maxA[n-1] = nums[n-1];\n        for(ll i = n-2;i>=0;i--){\n            if(nums[i] >= nums[i+1])        maxA[i] = maxA[i+1];\n            else{\n                ll diff = nums[i+1]-nums[i];\n                maxA[i] = maxA[i+1]-diff;\n                if(maxA[i]<0)       return 0;\n            }\n        }\n        \n        \n        // for(int i = 0;i<n;i++)      cout<<minA[i]<<" ";\n        // cout<<"\\n";\n        // for(int i = 0;i<n;i++)      cout<<maxA[i]<<" ";\n        // cout<<"\\n";\n        \n        ll dp[n][LIMIT];\n        memset(dp,0,sizeof(dp));\n        \n        for(ll i = minA[0];i<=maxA[0];i++){\n            dp[0][i] = 1;\n        }  \n        \n        for(ll i = 1;i<n;i++){\n            ll sum = 0;\n            ll k = 0;\n            \n            ll diff = minA[i]-minA[i-1];\n            \n            for(ll j = 0;j<minA[i-1];j++)       sum += dp[i-1][j];\n            for(ll j = minA[i];j<=maxA[i];j++){\n                sum += dp[i-1][minA[i-1]+(k++)];\n                sum %= MOD;\n                dp[i][j] = sum%MOD;\n                // cout<<dp[i][j]<<" ";\n            }\n            // cout<<"\\n";\n        }\n        long long ans = 0;\n        for(int i = 0;i<LIMIT;i++)     ans += dp[n-1][i];\n        return ans%MOD;\n    }\n};\n```
['C++']