This is my code , and i couldn’t understand why it is failing 1 test case …
Max_sum_k_parition , Getting wrong answer on one test case , may i know where i am going wrong
@aryan_007
Consider this testcase
6 5
5 -4 -3 -2 -1 10
Output should be “10” (no element from 1st block and 10 from second block) but your code is giving “9” as output (-1 from 1st block and 10 from second block).
@aryan_007
Consider this testcase too.
6 1
5 4 3 2 1 10
Ans should be “18” (5+3+10 =18) but your code is giving “10”
@aryan_007
There are few mistakes in your code
- what if size of your pq is 1 then your p_max2 doesn’t exist. Make a case when pq.size()==0 then p_max2={0,0}
- In your case you were taking atleast one element from each block which is not the required condition. So you know need to create priority_queue for each iteration. Also don’t pop any element.
- Your initial max_sum = -1 *10^18 not INT_MAX.
I have made changes in your code and it’s working fine for all testcase. Check it here
Thank you so so much sir !! My problem is solved now
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.