Skip to content

Instantly share code, notes, and snippets.

@sukeesh
Created May 28, 2015 06:01
Show Gist options
  • Save sukeesh/e407dbc9b35b8b9cd6e0 to your computer and use it in GitHub Desktop.
Save sukeesh/e407dbc9b35b8b9cd6e0 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
int main()
{
while(1)
{
int t,n=1;
scanf("%d",&t);
if(t==0)
{
return 0;
}
int a[t],i;
for(i=0;i<t;i++)
{
scanf("%d",&a[i]);
}
vector <int> dest(0);
vector <int> side(0);
for(i=0;i<t;i++)
{
if(a[i]==n)
{
dest.push_back(n);
n++;
a[i]=0;
}
else if(side.size()>0 && side.back()==n)
{
dest.push_back(n);
side.pop_back();
n++;
i--;
}
else if(a[i]!=0)
{
if(side.size()>0)
{
if(a[i]>side.back())
{
printf("no\n");
goto s;
}
}
side.push_back(a[i]);
a[i]=0;
}
}
printf("yes\n");
s:{}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment