Here is my code for STPAR ...i m getting TLE ...Plz help.... !!!
#include<iostream>
#include<stack>
#include<cstdio>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n) && n)
{
stack <int> s;
int i,count=1,flag=0,tmp;
for(i=0;i<n;i++)
{
scanf("%d",&tmp);
while(!s.empty() && (s.top()==count))
{
count++;
s.pop();
}
if(count==tmp)
count++;
else if(!s.empty() && (s.top()<tmp))
{
flag=1;
break;
}
else
s.push(tmp);
}
if(flag==0)
printf("yes\n");
else
printf("no\n");
}
return 0;
}