97rajmath's blog

By 97rajmath, history, 6 weeks ago, In English

This problem was quite easy and I coded it and checked it in my local machine. And it was giving me the right answer.(passing all the pretests) but for some reason after submitting the ONLINE_JUDGE was giving me a WRONG_ANSWER response. Here is the code. Can anyone tell me what's wrong in it?

int main(){

int t;
scanf("%d",&t);
while(t--){
    int n;ll m;

    scanf("%d",&n);
    scanf("%d",&m);

    ll a[n],sum=0;
    for(int i=0;i<n;i++)
       scanf("%d",&a[i]);       

    for(int i=0;i<n;i++)
       sum+=a[i];

    if((int)sum==m)
       cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;
}   
return 0;

}

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

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

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

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

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

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

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

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

You have used wrong format specifier for long long. Maybe that can be a reason .

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

    I defined it before.

    define ll long long

    And everything worked fine in my computer and was giving the correct output. But the Online Judge gave a WRONG_ANSWER response. Don't know why. It was solved when I tried doing it only using int .Then the code was accepted.

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

      i am talking about "%d" you should use "%lld" . sometime it gives correct output on local machine but this is not the case on online judge.