Slide window(to left/right)
Intuition(Be careful type cast in c#)ApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
(Be careful type cast in c#)
# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```csharp []
public class Solution {
    public long MaximumCoins(int[][] coins, int k) {
        int len = coins.Length;
        long totalScore = 0, curSum = 0;
        coins = coins.OrderBy(x => x[0]).ToArray();
        // slide window -> to right:
        int j = 0;
        for (int i = 0; i < len; i++)
        {
            while (j < len && coins[j][1] - coins[i][0] < k)
            {
                long nextVal = (long)(coins[j][1] - coins[j][0] + 1) * coins[j][2];
                curSum += nextVal;
                j++;
            }
            long rest = 0;
            if (j < len)
            {
                rest = Math.Max(rest, (long)(coins[i][0] + k - 1 - coins[j][0] + 1) * coins[j][2]);
            }

            totalScore = Math.Max(totalScore, curSum + rest);
            curSum -= (long)(coins[i][1] - coins[i][0] + 1) * coins[i][2];
        }

        // slide window -> to left:
        j = len - 1;
        curSum = 0;

        for (int i = len - 1; i >= 0; i--)
        {
            while (j >= 0 && coins[i][1] - coins[j][0] < k)
            {
                curSum += (long)(coins[j][1] - coins[j][0] + 1) * coins[j][2];
                j--;
            }

            long rest = 0;
            if (j >= 0)
            {
                rest = Math.Max(rest, (long)(coins[j][1] - (coins[i][1] - k + 1) + 1) * coins[j][2]);
            }
            totalScore = Math.Max(totalScore, curSum + rest);
            curSum -= (long)coins[i][2] * (coins[i][1] - coins[i][0] + 1);
        }

        return totalScore;
    }
}
```
['C#']