
import math
import os
import random
import re
import sys


def arrayManipulation(n, queries):
    array = [0] * n
    for a, b, k in queries:
        # Start is a - 1 because this is a one indexed array
        for i in range(a - 1, b):
            array[i] += k
            print(array)
    return max(array)


if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    nm = input().split()
    n = int(nm[0])
    m = int(nm[1])
    queries = []

    for _ in range(m):
        queries.append(list(map(int, input().rstrip().split())))

    result = arrayManipulation(n, queries)
    fptr.write(str(result) + '\n')
    fptr.close()


import math
import os
import random
import re
import sys


def arrayManipulation(n, queries):
    # An array used to capture the difference of an element
    # compared to the previous element.
    # Therefore the value of diffs[n] after all array manipulations is
    # the cumulative sum of values from diffs[0] to diffs[n - 1]
    diffs = [0] * n
    for a, b, k in queries:
        # Adds "k" to all subsequent elements in the array
        diffs[a - 1] += k
        # Ignore if b is out of range
        if (b < n):
            # Subtracts "k" from all subsequent elements in the array
            diffs[b] -= k

    sumSoFar = 0
    maxSoFar = 0
    for diff in diffs:
        sumSoFar += diff
        if sumSoFar > maxSoFar:
            maxSoFar = sumSoFar
    return maxSoFar


if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    nm = input().split()
    n = int(nm[0])
    m = int(nm[1])
    queries = []

    for _ in range(m):
        queries.append(list(map(int, input().rstrip().split())))

    result = arrayManipulation(n, queries)
    fptr.write(str(result) + '\n')
    fptr.close()

Improve runtime by using an array of diffs
Improve runtime by using an array of diffs

  
  import math
  import os
  import random
  import re
  import sys
  
  
  def arrayManipulation(n, queries):
-     array = [0] * n
+     # An array used to capture the difference of an element
+     # compared to the previous element.
+     # Therefore the value of diffs[n] after all array manipulations is
+     # the cumulative sum of values from diffs[0] to diffs[n - 1]
+     diffs = [0] * n
      for a, b, k in queries:
-         # Start is a - 1 because this is a one indexed array
-         for i in range(a - 1, b):
-             array[i] += k
-             print(array)
+         # Adds "k" to all subsequent elements in the array
+         diffs[a - 1] += k
+         # Ignore if b is out of range
+         if (b < n):
+             # Subtracts "k" from all subsequent elements in the array
+             diffs[b] -= k
+ 
+     sumSoFar = 0
+     maxSoFar = 0
+     for diff in diffs:
+         sumSoFar += diff
+         if sumSoFar > maxSoFar:
+             maxSoFar = sumSoFar
-     return max(array)
+     return maxSoFar
  
  
  if __name__ == '__main__':
      fptr = open(os.environ['OUTPUT_PATH'], 'w')
      nm = input().split()
      n = int(nm[0])
      m = int(nm[1])
      queries = []
  
      for _ in range(m):
          queries.append(list(map(int, input().rstrip().split())))
  
      result = arrayManipulation(n, queries)
      fptr.write(str(result) + '\n')
      fptr.close()
  
Improve runtime by using an array of diffs
## Code Before:

import math
import os
import random
import re
import sys


def arrayManipulation(n, queries):
    array = [0] * n
    for a, b, k in queries:
        # Start is a - 1 because this is a one indexed array
        for i in range(a - 1, b):
            array[i] += k
            print(array)
    return max(array)


if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    nm = input().split()
    n = int(nm[0])
    m = int(nm[1])
    queries = []

    for _ in range(m):
        queries.append(list(map(int, input().rstrip().split())))

    result = arrayManipulation(n, queries)
    fptr.write(str(result) + '\n')
    fptr.close()

## Instruction:
Improve runtime by using an array of diffs
## Code After:

import math
import os
import random
import re
import sys


def arrayManipulation(n, queries):
    # An array used to capture the difference of an element
    # compared to the previous element.
    # Therefore the value of diffs[n] after all array manipulations is
    # the cumulative sum of values from diffs[0] to diffs[n - 1]
    diffs = [0] * n
    for a, b, k in queries:
        # Adds "k" to all subsequent elements in the array
        diffs[a - 1] += k
        # Ignore if b is out of range
        if (b < n):
            # Subtracts "k" from all subsequent elements in the array
            diffs[b] -= k

    sumSoFar = 0
    maxSoFar = 0
    for diff in diffs:
        sumSoFar += diff
        if sumSoFar > maxSoFar:
            maxSoFar = sumSoFar
    return maxSoFar


if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    nm = input().split()
    n = int(nm[0])
    m = int(nm[1])
    queries = []

    for _ in range(m):
        queries.append(list(map(int, input().rstrip().split())))

    result = arrayManipulation(n, queries)
    fptr.write(str(result) + '\n')
    fptr.close()
