When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

Pankaj_Panwadi's blog

By Pankaj_Panwadi, history, 3 years ago, In English

I am getting WA for Test Set 2.

I looked at other people's solutions and also generated some random cases on both the correct and my solution, but both are giving the same answer.

Can anyone tell where I am getting it wrong?

My code

  • Vote: I like it
  • +8
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Try this:

1
2
99899 99

Output should be 3. Final array: 99899 99900

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Thanks for the help. I got it.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    I have got this case right. Also every other case i can imagine of. Still WA on 2nd test set. I did it using long long as the data type. Could that be a problem?

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I also overflowed. Since the minimal number that is larger than the last can be one digit longer, numbers can be up to 10^n = 10^100, far exceeding long long. There's a lot of ways to get around this like using strings.

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it +5 Vote: I do not like it

        The numbers can only go till 10^20 or 10^21 , in the case where all the given 100 elements are 10^9

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it +8 Vote: I do not like it

          If the list of n=100 numbers is 199, 198, ... 100, the optimal solution is 199, 1980, 19700, ... , 100...000. Where the last number has 101 zeros.

          • »
            »
            »
            »
            »
            »
            3 years ago, # ^ |
              Vote: I like it +2 Vote: I do not like it

            Actually an even easier case is just all numbers = 1.

            • »
              »
              »
              »
              »
              »
              »
              3 years ago, # ^ |
              Rev. 3   Vote: I like it +13 Vote: I do not like it

              No bro, if all numbers are 1

              Input: 1 1 1 1 1 1 1 ......(100 1s)
              Output: 1 10 11 12 13 ...19 100 101 102....
              
            • »
              »
              »
              »
              »
              »
              »
              3 years ago, # ^ |
                Vote: I like it +8 Vote: I do not like it

              Yah you are right on your first example, sorry, thanks

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it +8 Vote: I do not like it

        codicon thanks a lot!

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it +8 Vote: I do not like it

        codicon Thanks man. Just tried using strings and it worked. Regret the fact that I knew what may have gone wrong but still didnt change it.