Easy iterate on array rather than on axis
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# 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
```cpp []
class Solution {
public:
    #define ll long long
    long long maximumCoins(vector<vector<int>>& arr, int k){
        sort(arr.begin(),arr.end()); int n = arr.size();
        
        ll i = 0; ll j = 0; ll ans = 0; ll curr = 0;
        for(int i=0;i<n;i++){
            while(j<n && arr[j][1]-arr[i][0]+1<=k){
                curr+=((1ll* arr[j][1]-arr[j][0]+1)*arr[j][2]);
                j++;
            }
            ll par = 0;
            if(j<n && arr[j][0]<=arr[i][0]+k-1){
                par =((1ll* arr[i][0]+k-1-arr[j][0]+1)*arr[j][2]);
                curr+=par;
            }
            ans = max(ans,curr);
            curr-=(1ll * arr[i][1]-arr[i][0]+1)*arr[i][2];
            curr-=par;
            
        }

        j=n-1; curr = 0;
        for(int i=n-1;i>=0;i--){
            while(j>=0 && arr[i][1]-arr[j][0]+1<=k){
                curr+=((1ll* arr[j][1]-arr[j][0]+1)*arr[j][2]);
                j--;
            }
            ll par = 0;
            if(j>=0 && arr[i][1]-arr[j][1]+1<=k){
                par =((1ll *arr[j][1]-(arr[i][1]-k+1)+1)*arr[j][2]);
                curr+=par;
            }
            ans = max(ans,curr);
            curr -= ((1ll *arr[i][1]-arr[i][0]+1)*arr[i][2]);
            curr-=par;
        }

        return ans;



    }
};
```
['C++']