Doubt in hackerblock problem

can anyone provide solution of hackerblock problem valentine magic

problem can be done by:

  1. sort the candies and chocolates arrays.
  2. now its a DP problem where you have to match all boys to some girls.(think of some DP recurrence)
    for solution you may find editorial/solution here
    https://hack.codingblocks.com/app/contests/1209/281/problem

i have solved without using dynamic programming is my approach wrong

bro are u going to reply or should i repost my doubt

Yeah sure I, sorry for the delay

See you have to assign each boy exactly one girl, which is not the case with your implementation.
Example test case:
2 2
2 2
2 4
here answer is 2, but your output is 0.

but what i did is that paired boy with all the girls and finally pair it with the girl through which we get absolute minimum by using 2 loops more than one boy do not get the same girl for that i have even used variable k but why my output is still wrong

The k you used is of no use.
it will always store b1[b] which is garbage value.

then we do k=ans will that work?

No! with such approach you can only avoid pairing with last paired girl!

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.