Simple sliding window

```java []
class Solution {
    public long maximumCoins(int[][] c, int k) {
        long ans=0;   
        Arrays.sort(c,(a,b)->a[0]-b[0]);
        int kk=k;
        int s=0;
        long max=0;
        int j=0;
        int n=c.length;
        for(int i=0;i<n;i++){
            while(j<n&&c[j][1]-c[i][0]+1<=k){
                ans+=(long)(c[j][1]-c[j][0]+1)*(long)(c[j][2]);
                j++;
            }
            if(j<n){
            long p=(long)(c[j][2])*(long)(k-c[j][0]+c[i][0]);
              if(p>=0){
                max=Math.max(max,p+ans);
              }
            }
            ans-=(long)(c[i][1]-c[i][0]+1)*(long)(c[i][2]);
        }
        j=0;
        ans=0;
        for(int i=0;i<n;i++){
             ans+=(long)(c[i][1]-c[i][0]+1)*(long)(c[i][2]);
             while(k<c[i][1]-c[j][1]+1){
                 ans-=(long)(c[j][1]-c[j][0]+1)*(long)(c[j][2]);
                j++;
             }
             long p=Math.max(0,-k+c[i][1]-c[j][0]+1)*(long)(c[j][2]);
             max=Math.max(max,ans-p);
        }
        return max;
    }
}
```
['Java']