Problem from CF EDU.
In this problem, you need to write a segment tree to find the segment with the maximum sum.
Input: The first line contains two numbers $$$n$$$ and $$$m$$$ ($$$1 ≤ n, m ≤ 100000$$$), the size of the array and the number of operations. The next line contains $$$n$$$ numbers $$$a_i$$$, the initial state of the array ($$$-10^9 ≤ v ≤ 10^9$$$ ). The following lines contain the description of the operations. The description of each operation is as follows: $$$i$$$ $$$v$$$, assign the value $$$v$$$ to the element with index $$$i$$$ ($$$0 ≤ i < n, -10^9 ≤ v ≤ 10^9$$$ ).
Output: Print $$$m+1$$$ lines: the maximum sum of numbers on a segment before all operations and after each operation. Please note that this segment may be empty (so the sum on it will be equal to $$$0$$$).
I am getting RTE for literally all possible submissions I can make. Here is my poor RTE'd submission.
Local testing showed that the second submission is working correctly for the value of n up to 10000, but for higher values, it is not.
Can anyone please explain the reason behind this weird behaviour and the way to fix it?