arham_doshi's blog

By arham_doshi, history, 5 years ago, In English

my code here is similar to tutorials code my logic is same and i am getting wa. tutorials code Your text to link here...

can you please tell what is wrong in my code or i am wa on 2nd testcase 581 th sub test case , can you tell me testcase were my code fails

thanks in advance.

story(if you want to read) i was solving this question and i got wa on contest , i thought that my logic would be wrong and i moved to next question .then i again saw the tutorial and i got exactly same logic , i again wrote the code(after seeing tutorial) and again wa .i compared my code here and tutorials code Your text to link here... and i couldn't find the difference .

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

»
5 years ago, # |
  Vote: I like it +9 Vote: I do not like it

You have takenint mx = -1e12 , mn = 1e12. I fear that int cannot hold a value that big(or small) and thus overflow might be a reason for your code's WA.

»
5 years ago, # |
  Vote: I like it +7 Vote: I do not like it
v[0]=a;
    int mxx=-1e12;
    fo(i,1,n+1){
        if(v[i]==-1)v[i]=a;
        mxx=max(mxx,abs(v[i]-v[i-1]));
    }    

You are using v[1]-a to compute min and Max Everytime. Even when the input array doesn't start with -1

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

    thank you so much sir i have tried to remove that error but still it is giving wa on same tc my new code

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +7 Vote: I do not like it
      if(v[i]!=-1&&v[i-1]==-1)
      { //  cout<<v[i]<<" ";
          mx=max(mx,v[i]);
          mn=min(mn,v[i]);
      }
      

      when first element of input array is !=-1, You are using it to compute min and max.