• + 1 comment

    Using Java 8 syntaxis:

    public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     int n = in.nextInt();
     int m = in.nextInt();
     long[] output = new long[n];
     IntStream.range(0,m).forEach(i -> { int a = in.nextInt()-1;
                                        int b = in.nextInt();
                                        int k = in.nextInt();
                                        output[a] += k;
                                        if(b < n) output[b] -= k; });
     AtomicLong sum = new AtomicLong(0);
     System.out.print(LongStream.of(output).map(sum::addAndGet)
                                           .max().getAsLong());
     in.close();
    }