• + 6 comments

    I also did it on Java. At first, it only passed up to test 3, due some precision loss, having int k instead of long k. This may be obvious to many here, but I still thought it was interesting to see how such a small detail changes it all. Here is the code (in comments, the code with int, which fails after test 3).

    import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;

    public class Solution {

    public static void main(String[] args) {
        int N, M, a, b;
        long k; // int k;
        Scanner in = new Scanner(System.in);
        N = in.nextInt();
        M = in.nextInt();
        long[] differenceArray = new long[N+1]; // int[] ...
        for (int i=0; i<M; i++) 
        {
            in.nextLine();
            a = in.nextInt(); 
            b = in.nextInt();
            k = in.nextLong(); // in.nextInt();
            differenceArray[a] += k;
            if (b+1<=N)
                differenceArray [b+1] -= k;
        }
    
        long max = 0, addedDifference = 0; // int
        for (int i=1; i<=N; i++) 
        {
            addedDifference = addedDifference + differenceArray[i];
            if (max < addedDifference)
                max = addedDifference;
        }
        System.out.println(max);
        in.close();
    
    }
    

    }