O(n) solution in cpp
Code

# Code
```cpp []
class Solution
{
    public:
        int sumOfGoodNumbers(vector<int> &nums, int k)
        {
            int ans = 0, n = nums.size();
            for (int i = 0; i < n; i++)
            {
                bool isCorrect = true;
                if (i - k >= 0 && nums[i - k] >= nums[i])
                {
                    isCorrect = false;
                }
                if (i + k < n && nums[i + k] >= nums[i])
                {
                    isCorrect = false;
                }
                if (isCorrect)
                    ans += nums[i];
            }

            return ans;
        }
};
```
['C++']