### byee's blog

By byee, history, 17 months ago,

Hi all, I am trying to solve this question,I got some logic and implemented it but getting WA on test case 11. Here is my code.

Don't know whats wrong with my logic or code as I have tried many cases by myself, for all of them I got the correct output.

• -19

 » 17 months ago, # | ← Rev. 2 →   +14 Can you please briefly explain what everything in your code does? People aren't interested in debugging unreadable and unannotated code.Anyway this is how you can get out of those situations: make a program to generate thousands of small test cases. Make another "naive" solution (or in this case you can copy someone's accepted solution) and compare the outputs on the small test cases. This way you're bound to find a small test case where your program gives the wrong output. Then you can find out where your logic is wrong.
•  » » 17 months ago, # ^ |   0 Sorry sir, I've updated it. Please have look at it.
•  » » » 17 months ago, # ^ | ← Rev. 4 →   0 So all you do is try to leave the $K$ most common numbers in place and move the rest? Why didn't you just say so? (As an aside, the comments in your code aren't super useful, because they describe what you are doing instead of why you're doing them. The most useful thing for you would've been to say the first sentence in this comment. But it's nice you put in the effort anyway.)Anyway, this is wrong because it ignores the part about choosing $l$ and $r$, moving the numbers smaller than $l$ to $l$ and the numbers larger than $r$ to $r$. Consider the following test case: you can accommodate 4 different numbers and the numbers are: 1 1 1 1 1 2 3 4 5 5 5 5 5 Your solution claims that we only need to change one value. But really, we have to change five values.
•  » » » » 17 months ago, # ^ |   0 thank you very much, I'm more clear about my logic now and also got why the other AC solution uses prefix sum array. Its really silly mistake, I'll try to never repeat this again in future.the comments in your code aren't super useful, because they describe what you are doing instead of why you're doing themI'll take care of it in future. Thanks for your help.
 » 17 months ago, # |   0 Don't know whats wrong with my logic or codeNeither do we
 » 17 months ago, # |   0 Auto comment: topic has been updated by byee (previous revision, new revision, compare).