You are viewing a single comment's thread. Return to all comments →
Yes, that makes more sense and saves on memory and running time. Using a defaultdict in Python:
from collections import defaultdict sums = defaultdict(int) _, n_ranges = (int(x) for x in input().split()) for _ in range(n_ranges): start, stop, value = (int(x) for x in input().split()) sums[start] += value sums[stop+1] -= value max_val = running_val = 0 for _, val in sorted(sums.items()): running_val += val max_val = max(max_val, running_val) print(max_val)
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 →
Yes, that makes more sense and saves on memory and running time. Using a defaultdict in Python: