Please read the new rule regarding the restriction on the use of AI tools. ×

[Help] Segment with the Maximum Sum

Revision en2, by gjain_7, 2023-09-03 21:46:09

[Help] Segment with the Maximum Sum

I am getting WA on test 28 of this problem. Would really appreciate all the help.

My Approach

Basically, I am partitioning each segment $$$[l \ldots r]$$$ into three partitions, $$$p_1, p_2, p_3$$$ where
$$$p_2$$$ = maximum subarray sum in $$$[l \ldots r]$$$
$$$p_1$$$ = remaining left side sum
$$$p_3$$$ = remaining right side sum
$$$p_1+p_2+p_3 = \sum{a[l \ldots r]}$$$

Now to combine two arrays, the maximum subarray sum of the combined array would be $$$\max{(p_2^{(1)}, p_2^{(2)}, p_2^{(1)}+p_3^{(1)}+p_1^{(2)}+p_2^{(2)})}$$$.
The remaining left and right side parts can be maintained easily.

The final answer will be $$$p_2$$$ of the root of the segment tree.

My Code

Thank you in advance!

Tags segment tree, debugging, wrong answer

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English gjain_7 2023-09-04 06:49:13 8
en3 English gjain_7 2023-09-03 23:12:16 57 Tiny change: '[Help] Segment with the Maximum Sum\n==================\nI am getti' -> 'I am getti'
en2 English gjain_7 2023-09-03 21:46:09 641 Tiny change: ' segment $l...r$ into thr' -> ' segment $[l \cdots r]$ into thr' (published)
en1 English gjain_7 2023-09-03 21:18:25 2952 Initial revision (saved to drafts)