#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int N, max = 0, cnt = 0;
cin >> N;
int a[N], b[N], c[N];
for(int i = 0; i < N; i++){
cin >> a[i];
b[i] = a[i];
}
sort(a, a + N);
for(int i = 0; i < N; i++){
if(b[i] > max) max = b[i];
if(a[i] == b[i] && a[i] == max)
c[cnt++] = a[i];
}
cout << cnt << endl;
if(cnt == 0) cout << endl;
for(int i = 0; i < cnt; i++){
if(i != 0) cout << " ";
cout << c[i];
}
return 0;
}
https://www.cnblogs.com/fromzore/p/9600974.html