Q:

how come my c++ code gives 2 different outputs in ideone and codeforces custom test?

ideone:https://ideone.com/Ba3Nw7
#include <iostream>
using namespace std;

int main() {
int i,n,b25,b50,temp;
cin>>n;
for(i=0;i<n;i++)
{
    cin>>temp;
    if(temp==25)
        b25++;
    else if(temp==50)
    {
        if(b25>0)
        {
        b25--;
        b50++;
        }  
        else
        {
            cout<<"NO";
            return 0;
        }

    } 
    else if(temp==100)
    {
        if(b25>0 && b50>0)
        {   
            b25--;
            b50--;
        } 
        else if(b25>2)
            b25-=3;
        else
        {
            cout<<"NO";
            return 0;    
        }
    }
}
  cout<<"YES";
  return 0;
}

the test case tried is:
2
25 100
the output on ideone is "NO" which is the correct answer but on the codeforces custom test it gives a "YES",why is that?

A:

One very glaring mistake I can see is not initialising variables b25 and b50. 
In your code, you are continuously incrementing and decrementing the two variables, and therefore, your answer goes wrong every time. 
I would suggest: 
int i,n,b25=0,b50=0,temp=0;

You might be getting a right or a wrong answer because arbitrarily any value can get stored in b25 and b50. Sometimes it may satisfy the NO condition, and at other times, a YES condition.

Had your variables been static or within file scope, they would have been initialised as 0. However, your variable is locally defined, hence its value will be indeterminate, invoking undefined behaviour.

