#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100010]={0},maxx[100010]={0},minn[100010]={0},ans[100010]={0};
int main(){
int i, n, max=0, min=1000000000;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
if(a[i]>max)max=a[i];
maxx[i]=max;
}
for(i=n-1;i>=0;i--){
if(a[i]<min)min=a[i];
minn[i]=min;
}
if(n==1){printf("1\n");printf("%d",a[0]);}
else{
int index=0;
if(a[0]<minn[1]){ans[index++]=a[0];}
for(i=1;i<n-1;i++){
if(a[i]>maxx[i-1]&&a[i]<minn[i+1]){ans[index++]=a[i];}
}
if(a[n-1]>maxx[n-2]){ans[index++]=a[i];}
printf("%d\n",index);
for(i=0;i<index;i++){
printf("%d",ans[i]);
if(i<index-1)printf(" ");
}
}
printf("\n");
return 0;
}
PAT-B1045
最新推荐文章于 2022-02-26 23:23:41 发布