#include<stdio.h>
int main()
{
int n,m,i,j,e,a[100],t1,t2;
while(scanf("%d%d",&n,&m)!=EOF&&(n!=0||m!=0))
{
scanf("%d",&a[0]);
i=1;
while(i<n)
{
scanf("%d",&a[i]);
if(a[i]>a[i-1])
i++;
}
if(m>a[n-1])
a[n]=m;
else
{
for(i=0;i<n;i++)
{
if(m<a[i])
{
t1=a[i];
a[i]=m;
for(j=i+1;j<=n;j++)
{
t2=a[j];a[j]=t1;t1=t2;
}
break;
}
}
}
for(e=0,i=0;i<=n;i++)
{
if(e!=0)
printf(" ");
printf("%d",a[i]);
e++;
}
printf("\n");
}
return 0;
}
Time Limit Exceeded
code2:
#include<stdio.h>
int main()
{
int n,m,i,j,e,a[100],t1,t2,*p=a;
while(scanf("%d%d",&n,&m)!=EOF&&(n!=0||m!=0))
{
scanf("%d",p);
i=1;
while(i<n)
{
scanf("%d",p+i);
if(*(p+i)>*(p+i-1))
i++;
}
if(m>a[n-1])
a[n]=m;
else
{
for(i=0;i<n;i++)
{
if(m<a[i])
{
t1=a[i];
a[i]=m;
for(j=i+1;j<=n;j++)
{
t2=a[j];a[j]=t1;t1=t2;
}
break;
}
}
}
for(e=0,p=a;p<=(a+n);p++)
{
if(e!=0)
printf(" ");
printf("%d",*p);
e++;
}
printf("\n");
}
return 0;
}