Sliding window. Optimal solution
```
class Solution:
    def maximumCoins(self, coins: List[List[int]], k: int) -> int:
        coins.sort(key = itemgetter(0))
        i, total, ans, n = 0, 0, 0, len(coins)
        l0, r0, c0 = coins[0]
        for l, r, c in coins: 
            while i < n and r - coins[i][0] + 1 >= k:    
                l0, r0, c0 = coins[i]
                ans = max(total + max(k + l0 - l, 0) * c,  ans)             
                total -= (r0 - l0 + 1) * c0
                i += 1
            total += (r - l + 1) * c
            if i < n and coins[i][0] != l0:
                ans = max(total + max(k + r0 - r, 0) * c0,  ans)  
        return max(ans, total)
```
['Sliding Window', 'Python3']