[CODE ONLY][DEBUG OUTPUT] PYTHON USING Alex Wice's SLIDING WINDOW SOLUTION
Code
# Code
```python3 []
# Using Alex Wice's sliding window
# https://leetcode.com/problems/maximum-coins-from-k-consecutive-bags/solutions/6232234/python-sliding-window-by-awice-i1sv

class Solution:
    def maximumCoins(self, coins: List[List[int]], k: int) -> int:
        n = len(coins)

        def helper(h_coins:  List[List[int]]) -> int:
            h_coins.sort()
            local_grab = 0
            full_slots = 0
            rhs = 0

            for i, coin_segment in enumerate(h_coins):
                # print(f'Starting at {i}... and {coin_segment}')
                start, end, value = coin_segment
    
                while rhs + 1 < n:  # Get full windows
                    peak_next_start = h_coins[rhs + 1][0]
                    next_start_contained_in_grab = peak_next_start < start + k
                    if not next_start_contained_in_grab:
                        # print(f'\tDONE. Retrieved all full windows...')
                        break
                    # The next rhs window is fully contained...
                    adj_start, adj_end, adj_value = h_coins[rhs]
                    full_slots += (adj_end - adj_start + 1) * adj_value  # Add one because inclusive range.
                    # print(f'\tTAKE full window of {h_coins[rhs]} at {(adj_end - adj_start + 1) * adj_value}')

                    rhs += 1

                partial_slots = 0

                partial_segment_start = h_coins[rhs][0]
                partial_segment_end = h_coins[rhs][1]
                partial_segment_value = h_coins[rhs][2]

                if rhs < n and partial_segment_start < start + k:
                    # print(f'\t\tHANDLE PARTIAL...')
                    rightmost = min(start + k - 1, partial_segment_end)
                    # print(f'\t\t...rightmost is {rightmost}')
                    slots_taken = rightmost - partial_segment_start + 1
                    # print(f'\t\t......we can take {slots_taken} at {partial_segment_value} each.')
                    partial_slots += slots_taken * partial_segment_value
                # print(f'\tlocal best = max({local_grab}, {full_slots + partial_slots})')
                local_grab = max(local_grab, full_slots + partial_slots)
                # print(f'\t...finally adjust {full_slots} by taking away {end - start + 1} * {value}')
                full_slots -= (end - start + 1) * value # Take curr away

            return local_grab
        forward_grab = helper(coins)
        # print(f'\n...\nREVERSING SLOTS\n...\n')
        for i, each_segment in enumerate(coins):  # Reverse
            start, end, value = each_segment
            coins[i] = [end * -1, start * -1, value]
        backward_grab = helper(coins)
        return max(forward_grab, backward_grab)


# DEBUG OUTPUT
# Input
# coins =
# [[8,10,1],[1,3,2],[5,6,4]]
# k =
# 4
# Stdout
# Starting at 0... and [1, 3, 2]
# 	DONE. Retrieved all full windows...
# 		HANDLE PARTIAL...
# 		...rightmost is 3
# 		......we can take 3 at 2 each.
# 	local best = max(0, 6)
# 	...finally adjust 0 by taking away 3 * 2
# Starting at 1... and [5, 6, 4]
# 	TAKE full window of [1, 3, 2] at 6
# 	TAKE full window of [5, 6, 4] at 8
# 		HANDLE PARTIAL...
# 		...rightmost is 8
# 		......we can take 1 at 1 each.
# 	local best = max(6, 9)
# 	...finally adjust 8 by taking away 2 * 4
# Starting at 2... and [8, 10, 1]
# 		HANDLE PARTIAL...
# 		...rightmost is 10
# 		......we can take 3 at 1 each.
# 	local best = max(9, 3)
# 	...finally adjust 0 by taking away 3 * 1

# ...
# REVERSING SLOTS
# ...

# Starting at 0... and [-10, -8, 1]
# 	DONE. Retrieved all full windows...
# 		HANDLE PARTIAL...
# 		...rightmost is -8
# 		......we can take 3 at 1 each.
# 	local best = max(0, 3)
# 	...finally adjust 0 by taking away 3 * 1
# Starting at 1... and [-6, -5, 4]
# 	TAKE full window of [-10, -8, 1] at 3
# 	TAKE full window of [-6, -5, 4] at 8
# 		HANDLE PARTIAL...
# 		...rightmost is -3
# 		......we can take 1 at 2 each.
# 	local best = max(3, 10)
# 	...finally adjust 8 by taking away 2 * 4
# Starting at 2... and [-3, -1, 2]
# 		HANDLE PARTIAL...
# 		...rightmost is -1
# 		......we can take 3 at 2 each.
# 	local best = max(10, 6)
# 	...finally adjust 0 by taking away 3 * 2















# Greedy Solution... TLE at test case 588...

        # coins.sort()

        # best_grab = 0
        # prev_end = 0
        # prev_size = 0

        # n = len(coins)

        # def grabAndForward(start_index: int) -> int:
        #     local_grab = 0
        #     remaining = k
        #     curr_index = start_index
        #     # print(f'[FORWARD] STARTING at index {i}')
        #     curr_segment_start = coins[i][0]
        #     last_end = curr_segment_start # Begin at start of first segment,
        #     while remaining > 0 and curr_index < n:
        #         # print(f'With local_grab={local_grab}, we have remaining={remaining} slots to fill...')
        #         # print(f'\tassessing coins[{curr_index}]: {coins[curr_index]}')
        #         curr_start, curr_end, curr_value = coins[curr_index]
        #         slots_to_get_to_curr_segment = curr_start - last_end
        #         # print(f'\t\tit took {slots_to_get_to_curr_segment} to get to {curr_start} from {last_end}...')
        #         remaining -= slots_to_get_to_curr_segment
        #         # print(f'\t\t\tthat means we have remaining={remaining} slots.')
        #         if remaining > 0:
        #             available_slots = (curr_end - curr_start) + 1 # Inclusive range, must add 1 to adjust
        #             # print(f'\t\t\t\twe have {available_slots} from [{curr_start},{curr_end}]')
        #             taken_slots = min(available_slots, remaining)
        #             # print(f'\t\t\t\t\twhich means we can take {taken_slots} for {curr_value} each')
        #             local_grab += taken_slots * curr_value
        #             remaining -= taken_slots
        #             # print(f'\t\t\t\t\t\twe have a new local_grab={local_grab} and new remaining={remaining}')
        #             # Update last_end
        #             last_end = curr_end + 1
        #             curr_index += 1
        #             continue
        #         # else:
        #             # print(f'\t\t\t\t...which means we have filled k.')

        #         break
        #     # print(f'\t...return {local_grab}')
        #     return local_grab


        # def grabAndReverse(start_index: int) -> int:
        #     local_grab = 0
        #     remaining = k
        #     curr_index = start_index
        #     # print(f'[REVERSE] STARTING at index {i}')
        #     curr_segment_end = coins[i][1]
        #     last_start = curr_segment_end # Begin at start of first segment,
        #     while remaining > 0 and curr_index >= 0:
        #         # print(f'With local_grab={local_grab}, we have remaining={remaining} slots to fill...')
        #         # print(f'\tassessing coins[{curr_index}]: {coins[curr_index]}')
        #         curr_start, curr_end, curr_value = coins[curr_index]
        #         slots_to_get_to_curr_segment = last_start - curr_end
        #         # print(f'\t\tit took {slots_to_get_to_curr_segment} to get to {curr_end} from {last_start}...')
        #         remaining -= slots_to_get_to_curr_segment
        #         # print(f'\t\t\tthat means we have remaining={remaining} slots.')
        #         if remaining > 0:
        #             available_slots = (curr_end - curr_start) + 1 # Inclusive range, must add 1 to adjust
        #             # print(f'\t\t\t\twe have {available_slots} from [{curr_start},{curr_end}]')
        #             taken_slots = min(available_slots, remaining)
        #             # print(f'\t\t\t\t\twhich means we can take {taken_slots} for {curr_value} each')
        #             local_grab += taken_slots * curr_value
        #             remaining -= taken_slots
        #             # print(f'\t\t\t\t\t\twe have a new local_grab={local_grab} and new remaining={remaining}')
        #             # Update last_end
        #             last_start = curr_start - 1
        #             curr_index -= 1
        #             continue
        #         # else:
        #             # print(f'\t\t\t\t...which means we have filled k.')

        #         break
        #     # print(f'\t...return {local_grab}')
        #     return local_grab


        # for i, _ in enumerate(coins):
        #     forward_grab = grabAndForward(i)
        #     reverse_grab = grabAndReverse(i)
        #     best_local = max(forward_grab, reverse_grab)
        #     best_grab = max(best_grab, best_local)


        # return best_grab

```
['Python3']