Doubt in the solution of SUBSUMS shared with us

The link to solution done by prateek bhaiya is https://ide.codingblocks.com/s/5974. I think the answer should not only consider the subarrays where one part is from sv1 and another from sv2 but it should also include cases where ans is purely from sv1 and purely from sv2 as well. Am i wrong???

Also please explan why the variable j is incremented only when a set bit is encountered (subsets function)? I am unable to trace that logic

If answer is from s1 to s2, then it would come in s2 na?
I didn’t get where are you getting confused

Why the answer is from s1 to s2??

The answers are all subarrays whose sum lies in given range of a,b. So we already have sum of all possible subarrays from each halve stored in sv1 and sv2. So, why arent we checking them for answers?
I think i am missing any point

Lets take an example -1 se 2
1 -2 3 is the array, lets get all subsets with sum in the range -1 to 2
Dry run this with the logic once by writing. I am sure you’ll get it.

Ya, I am getting a feeling ki while creating the subsets, zero will definitely come and this will ensure elements from sv2 are taken and similarly for each sv1, we will cover the zero of sv2 if that element is coming inside my given range.

Saying this, I am also worried ki contests m time boundations k saath kaise hoga itna lamba question!!

Doing this course will build concepts for you.
Yes, for now you might take an hour or maybe 2 for debugging and getting an AC, but by practicing more and more, you will get this question within 20 minutes.
I recommend you to first get your concepts strong so that you know how to solve the question, and then do time bound contests to gain speed.

1 Like