I am getting WA...tried with one or 2 cases but couldn;t find it

Can u please help me to get me one test case where I am wrong…and moreover please tell me some way so that I might reduce the length of my code…if possible…

HEY CAN ABYONE TELL ME THE TEST CASE OVER WHICH I AM GOING WRONG…

Hey @kaushikjatin
Sorry for the delayed response
Here is the solution code
Your approach needs little tweaking
You can see those modifications here https://ide.codingblocks.com/s/238898

Hey I have a doubt in your slution…that suppose the prices of items are 10 15 20 24 25 and the price for which we need to do query is 13 then how can your query() function work directly …firstly won;t you have to find the first element larger than 13 i.e. 15 here…by help of binary search and then call query(15)

@kaushikjatin
Not really
You know the max possible Y beforehand
So you’re just making updates to cumulative sum array
The ones which are not present will simply have 0 as their frequency
Won’t interfere with the answer

Okk…so if I am not wrong then you will be making an BIT aray of size (max value possible in the array of cost)…i.e if the max cost of a substance is 200005 posible then you r making this big array…actually I had done some space optimization …I compressed the values first…and then used some binary search to find the just greater weight… that’s why my solution is different actually

@kaushikjatin
That’s also a smart approach. Range compression. But yeah both are similar in the end.

Hey can u provide me one test case …for which I am getting wring answer…

@kaushikjatin
The actual test cases are too big so it won’t be feasible
Finding test cases which fail the code is hard I know you understand that :slight_smile:
So please try to find such cases by yourself or maybe you can see the approach I sent you and move to the next question
Better than spending so much time on a question I believe