Python3 ||  11 lines, three segments || T/S: 99% / 52%
Note that1 <= k <= floor(nums.length / 2). This constraint ensures that the three segments described below are non-empty.https://leetcode.com/problems/sum-of-go
Note that`1 <= k <= floor(nums.length / 2)`. This constraint ensures that the three segments described below are non-empty. 

```python3 []
class Solution:
    def sumOfGoodNumbers(self, nums: List[int], k: int) -> int:

        n, ans = len(nums), 0

            # First segment: check the first k elements
        for i in range(k): 
            if nums[i] > nums[i + k]:
                ans += nums[i]

            # Middle segment: check the elements from k to n-k
        for i in range(k, n - k): 
            if nums[i] > nums[i - k] and nums[i] > nums[i + k]:
                ans += nums[i]

            # Last segment: check the last k elements
        for i in range(n - k, n): 
            if nums[i] > nums[i - k]: 
                ans += nums[i]

        return ans
```
```cpp []
class Solution {
public:
    int sumOfGoodNumbers(vector<int>& nums, int k) {
        int ans = 0;
        int n = nums.size();

        // First segment: check the first k elements
        for (int i = 0; i < k; ++i) {
            if (i + k < n && nums[i] > nums[i + k]) {
                ans += nums[i];}}

        // Middle segment: check the elements from k to n-k
        for (int i = k; i < n - k; ++i) {
            if (nums[i] > nums[i - k] && nums[i] > nums[i + k]) {
                ans += nums[i];}}

        // Last segment: check the last k elements
        for (int i = n - k; i < n; ++i) {
            if (i - k >= 0 && nums[i] > nums[i - k]) {
                ans += nums[i];}}

        return ans;}};
```
```java []
class Solution {
    public int sumOfGoodNumbers(int[] nums, int k) {
        int ans = 0;
        int n = nums.length;

        // First segment: check the first k elements
        for (int i = 0; i < k; i++) {
            if (i + k < n && nums[i] > nums[i + k]) {
                ans += nums[i];}}

        // Middle segment: check the elements from k to n-k
        for (int i = k; i < n - k; i++) {
            if (nums[i] > nums[i - k] && nums[i] > nums[i + k]) {
                ans += nums[i];}}

        // Last segment: check the last k elements
        for (int i = n - k; i < n; i++) {
            if (i - k >= 0 && nums[i] > nums[i - k]) {
                ans += nums[i];}}

        return ans;}}
```
[https://leetcode.com/problems/sum-of-good-numbers/submissions/1544194217/](https://leetcode.com/problems/sum-of-good-numbers/submissions/1544194217/)

I could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(1), in which *N* ~ `len(nums)`.
['C++', 'Java', 'Python3']