• + 1 comment

    Oh that is clever. Very very clever. I was brute-forcing it (running every operation in full on every element from a to b) and every test from Test 5 onward was timing out.

    Here's my Python 3 implementation of your solution:

    n,m = map(int, input().split()))
    numbers = [0] * n
    value, maxval = 0,0
    for _ in range(m):
        a, b, k = map(int, input().split())
        numbers[a-1] += k
        if b < n: numbers[b] -= k
    for number in numbers:
        value += number
        if value > maxval: maxval = value
    print(maxval)