sliding window one pass soln.
IntuitionApproachsince the size of the array is 1e9 giving us the idea that computations will not be possible within time thus we pivot to using the intervals f
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
since the size of the array is 1e9 giving us the idea that computations will not be possible within time thus we pivot to using the intervals for our calculations hence using sliding window approach over intervals completely and not the indexes individually.

there can be a total of 4 cases of window out of which only two of them contribute to our answer because either of the intervals will have a higher value than the other thus it only makes sense of incorporate that interval as much as possible in our window to maximise our answer
thus either taking interval A(starting at A) completely or interval B(ending at B) completely

due to the constraint K there might be an onverlap in an interval which we will handle separately(addition/substraction from our total_sum).

# Complexity
- Time complexity:
O(nlogn + n) ~ O(nlogn).

- Space complexity:
O(1).

# Code
```cpp []
class Solution {
public:
    long long maximumCoins(vector<vector<int>>& coins, int k) {
        int n = coins.size();
        sort(coins.begin(), coins.end());
        long long result = 0, csum = 0, psum = 0;

        // intervals that necessarily start from the starting point of a range and taking that complete interval into consideration 
        for (int i = 0, j = 0; i < n; i++) {
            // Expanding the window such that complete intervals are considered(end points of range and not the coordinates in range)
            while (j < n && coins[j][1] <= coins[i][0] + k - 1) {
                csum += (long long)(coins[j][1] - coins[j][0] + 1) * coins[j][2];
                j++;
            }
            // Handling partial overlap such that an interval ends in the middle of a range and not at the ends of that range due to the CONSTRAINT "K" and thus taking the values of the partial overlap in that interval into consideration and summing it up with the currentsum(sum of complete intervals) thus giving us the total value for the size "K", hence maximising our result.
            if (j < n) {
                long long val = (long long)(coins[i][0] + k - 1 - coins[j][0] + 1) * coins[j][2];
                psum = (val>0)?val:0;
                result = max(result, csum + psum);
            }
            // Shrinking the window in case our window exceeds the given constraint "K" and thus removing the contributions of the intervals being shrinked(the addition and removal is being done of complete intervals and not of indexes individually due to time constraint).
            csum -= (long long)(coins[i][1] - coins[i][0] + 1) * coins[i][2];
        }

        csum = 0, psum = 0;
        //doing the same with intervals ending at the range end instead of starting from the range start
        for (int i = 0, j = 0; i < n; i++) {
            // Expand the window
            csum += (long long)(coins[i][1] - coins[i][0] + 1) * coins[i][2];
            while (j < n && coins[j][1] < coins[i][1] - k + 1) {
                csum -= (long long)(coins[j][1] - coins[j][0] + 1) * coins[j][2];
                j++;
            }
            // Handle partial overlap
            if (j < n) {
                long long val = (long long)(coins[i][1] - k - coins[j][0] + 1) * coins[j][2];
                psum = (val>0)?val:0;
                result = max(result, csum - psum);
            }
        }

        return result;
    }
};

```
['C++']