• + 1 comment

    Your solution is elegant:-In java:-

    import java.util.*;
    public class AlgorithmicCrush {
    	public static void main(String[] args) {
    		int n,m,a,b,k;
    		Scanner in=new Scanner(System.in);
    		n=in.nextInt();
    		m=in.nextInt();
    		long arr[]=new long[n];
    		long max=0,x=0;
    		for(int i=0;i<m;i++) {
    			a=in.nextInt();
    			b=in.nextInt();
    			k=in.nextInt();
    			arr[a-1]+=k;
    			if(b<=n-1)
    				arr[b]-=k;
    		}
    		for(int i=0;i<n;i++) {
    			x+=arr[i];
    			if(max<x)
    				max=x;
    		}
    		
    		System.out.print(max);
    	}
    
    }
    

    PS:-I really liked that your indexing goes from 1 to n in the array of size n+1.It's intuitive.Maybe that's a norm.Anyways,gonna learn more. :)