You are viewing a single comment's thread. Return to all comments →
import sys queries=sys.stdin.read().strip().split() it=iter(queries) n=int(next(it)) q=int(next(it)) arr = [0] * (n+2)
for i in range(q): a = int(next(it)) b = int(next(it)) k = int(next(it)) arr[ a ] += k arr[ b +1] -= k
max_value = 0 current = 0 for val in arr: current += val max_value = max(max_value, current)
print(max_value)
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
import sys queries=sys.stdin.read().strip().split() it=iter(queries) n=int(next(it)) q=int(next(it)) arr = [0] * (n+2)
for i in range(q): a = int(next(it)) b = int(next(it)) k = int(next(it)) arr[ a ] += k arr[ b +1] -= k
max_value = 0 current = 0 for val in arr: current += val max_value = max(max_value, current)
print(max_value)