• + 3 comments

    A Python 3 solution in O(M) time and space, solely independent of N. :)

    from itertools import accumulate
    from collections import defaultdict
    ar = defaultdict(int)
    for _ in range(int(input().split()[1])):
        p, q, k = map(int, input().split())
        ar[p] += k
        ar[q + 1] -= k
    print(max(accumulate(ar[i] for i in sorted(ar))))