He builds ceil(N/K) blocks of this array with size of each block as [i∗K+1,min((i+1)∗k,N)] for 0≤i≤N/K .
I failed to understand the size of each block? I mean why is it [,]?
He builds ceil(N/K) blocks of this array with size of each block as [i∗K+1,min((i+1)∗k,N)] for 0≤i≤N/K .
I failed to understand the size of each block? I mean why is it [,]?
Sorry for the delay, actually I had exams previously.
The array is divided into k blocks so,
1,…,k - 1 is the first block,
k,…,2 * k - 1 is the second block,
2 *k,…,3 * k - 1, is the third block,
… and so on.
So now you cannot select two elements from the same blocks. And for two consecutive elements in the subsequence their index difference should not be equal to k.
At starting make a priority_queue < pair ,<int,int> > and push {0,infinity}.
Traverse block-wise from end of the array to starting ,
or every element, choose a element from the next block and the difference between their indices should not be equal to k.
Consider N = 3, k = 2 and A = {30,10,25}
if 30 is selected then 25 cannot be selected for our subsequence, so our answer for this case was max(30,10 + 25) = 35
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.