cswork / OA打开练习工作台

VisaOA #5

Greater-Than-Neighbors Stabilization

估计简单可在线判题

考点(AI 标注)模拟/实现

Repeatedly filter the array simultaneously: keep the first and last elements, and the interior elements strictly greater than both their left and right neighbors; each round compares against the array as it was at the start of that round. Continue until a round makes no change, and return the final array.

输入格式

n (1≤n≤200000), followed by n integers (absolute value ≤10^9, site-added).

输出格式

Output the length of the final array and its elements.

样例 1

输入:

6
3 6 4 8 2 9

输出:

2 3 9

样例 2

输入:

1
1

输出:

1 1

样例 3

输入:

5
1 2 2 1 5

输出:

2 1 5