This is the HackerRank problem Algorithmic Crush:
You are given a list of size
N, initialized with zeroes. You have to perform
Moperations on the list and output the maximum of final values of all the
Nelements in the list. For every operation, you are given three integers
k. The value
kneeds to be added to all the elements ranging from index a through
The first line will contain two integers
Mseparated by a single space.
Mlines will each contain three integers
The numbers in the list are numbered from
A single integer on a separate line line containing maximum value in the updated list.
\$3 ≤ N ≤ 10^7\$
\$1 ≤ M ≤ 2 \cdot 10^5\$
\$1 ≤ a ≤ b ≤ N\$
\$0 ≤ k ≤ 10^9\$
5 3 1 2 100 2 5 100 3 4 100
After the first update, the list will be
100 100 0 0 0.
After the second update, the list will be
100 200 100 100 100.
After the third update, the list will be
100 200 200 200 100.
So, the required answer will be
This is my Python 3 solution:
tempArray = [int(n) for n in input().split(" ")] N = tempArray M = tempArray arr = [0 for x in range(N)] for i in range(0,M): tempArray = [int(n) for n in input().split(" ")] for j in range(tempArray-1, tempArray): arr[j] = arr[j] + tempArray print(max(arr))
It gives me running time-out error for some test cases. I know very little about time complexity but I think it's \$O(NM)\$. What am I doing wrong?