sliding window
```python3 []
class Solution:
    def maximumCoins(self, coins: List[List[int]], k: int) -> int:
        coins.sort()
        n = len(coins)

        def _solve(coins):
            ans = j = C = 0
            for i, (l, r, c) in enumerate(coins):
                while j < n and coins[j][1] - l + 1 < k:
                    C += coins[j][2] * (coins[j][1] - coins[j][0] + 1)
                    j += 1
                if j == n:
                    ans = max(ans, C)
                else:
                    L = max(0, k - (coins[j][0] - l))
                    ans = max(ans, C + L * coins[j][2])
                C -= c * (r - l + 1)
            return ans

        M = max(x[1] for x in coins)
        coinsReversed = sorted([(M - r, M - l, c) for l, r, c in coins])
        return max(_solve(coins), _solve(coinsReversed))

```
['Python3']