ss6364's blog

By ss6364, history, 5 weeks ago, In English,

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.

Also please help me in understanding this submission for the same why he used prefix sum and how it is different from my logic. Please help me. Thanks.

 
 
 
 
  • Vote: I like it
  • -19
  • Vote: I do not like it

»
5 weeks ago, # |
Rev. 2   Vote: I like it +14 Vote: I do not like it

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.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Sorry sir, I've updated it. Please have look at it.

    • »
      »
      »
      5 weeks ago, # ^ |
      Rev. 4   Vote: I like it 0 Vote: I do not like it

      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.

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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 them

        I'll take care of it in future. Thanks for your help.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Don't know whats wrong with my logic or code

Neither do we

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ss6364 (previous revision, new revision, compare).