302008: CF381B. Sereja and Stairs

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Sereja and Stairs

题意翻译

给定 $m$ 个元素的序列 $b$ ,取若干 $b$ 中元素组成新序列 $a$ 使得 $a_1<a_2<a_3<\dotsc<a_{i-1}<a_i>a_{i+1}>\dotsc>a_{|a|-1}>a_{|a|}$。给出一种使得 $|a|$ 最大的方案。

题目描述

Sereja loves integer sequences very much. He especially likes stairs. Sequence $ a_{1},a_{2},...,a_{|a|} $ ( $ |a| $ is the length of the sequence) is stairs if there is such index $ i $ $ (1<=i<=|a|) $ , that the following condition is met: $ a_{1}&lt;a_{2}&lt;...&lt;a_{i-1}&lt;a_{i}&gt;a_{i+1}&gt;...&gt;a_{|a|-1}&gt;a_{|a|}. $ For example, sequences \[1, 2, 3, 2\] and \[4, 2\] are stairs and sequence \[3, 1, 2\] isn't. Sereja has $ m $ cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?

输入输出格式

输入格式


The first line contains integer $ m $ $ (1<=m<=10^{5}) $ — the number of Sereja's cards. The second line contains $ m $ integers $ b_{i} $ $ (1<=b_{i}<=5000) $ — the numbers on the Sereja's cards.

输出格式


In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.

输入输出样例

输入样例 #1

5
1 2 3 4 5

输出样例 #1

5
5 4 3 2 1

输入样例 #2

6
1 1 2 2 3 3

输出样例 #2

5
1 2 3 2 1

Input

题意翻译

给定 $m$ 个元素的序列 $b$ ,取若干 $b$ 中元素组成新序列 $a$ 使得 $a_1<a_2<a_3<\dotsc<a_{i-1}<a_i>a_{i+1}>\dotsc>a_{|a|-1}>a_{|a|}$。给出一种使得 $|a|$ 最大的方案。

加入题单

算法标签: