# Need Help in question of CODIGO

Help me in mathematical approach need for question pennya and candies!

check here for question

1 Like

Thank you for participating.

In the problem first, you have to sort the given array and treat every candy different from each other as even if they have the same values.

Now after that you have to move in the entire array and use binary search (upper bound) like this bsearch(arr, p * arr[i], i, n) by that you can get the range for selection the candy with candy i.

One thing is that upper bound will give 1 index higher than the required index so use index-=1 and after that calculate NCR(index-i, k-1), (k-1 because you have already selected the i^{th} candy).

Now as Constraints for n is 10^5 you need to pre-compute the factorial values and use them in finding the NCR.

We will try to publish the editorial as soon as possible.

1 Like

i finally got it after seeing some of the solutions,
i think there should be NCR(index-i,k-1) because we have to make combinations from arr[i] to P*arr[i] elements.

Thanks for helping!

Sorry I missed that thanks for pointing

//