[c++][o(NlogN) solution)
Code

# Code
```cpp []
class Solution {
public:
    long long maximumCoins(vector<vector<int>>& coins, int k) {
        sort(coins.begin(),coins.end());
        int sz=coins.size(), idx=-1;
        vector<long long> ps(sz+1);
        for (int i=1;i<=sz;i++){
            ps[i] = ps[i-1] + 1ll*(coins[i-1][1]-coins[i-1][0]+1)*coins[i-1][2];
        }

        long long ans=0;
        auto l = [](const vector<int>& entry, int v){
            return entry[1]<v;
        };
        long long s1,s2;
        for (int i=0;i<sz;i++){
            idx = lower_bound(coins.begin()+i,coins.end(),coins[i][0]+k-1, l)-coins.begin();
            s1 = ps[idx]-ps[i];
            s2 = 0;
            
            if (idx<sz){
                s2 = 1ll*max(0,coins[i][0]+k-coins[idx][0])*coins[idx][2];
            }
            //cout << "postfix " << idx << " " << s1 << " " << s2 << endl;
            ans = max(ans, s1+s2);
            idx=lower_bound(coins.begin(),coins.end(),coins[i][1]-k+1, l)-coins.begin();
            s1 = ps[i+1]-ps[idx+1];
            s2 = 1ll*(coins[idx][1]-max(coins[i][1]-k+1,coins[idx][0])+1)*coins[idx][2];
            //cout << "prefix " << idx << " " << s1 << " " << s2 << endl;
            ans = max(ans,s1+s2);

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