CF381B.Sereja and Stairs
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 < _a_2 < ... < a__i - 1 < a__i > a__i + 1 > ... > a|a| - 1 > 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?
Sereja 非常喜欢整数序列,尤其钟爱“阶梯”序列。
序列 a1,a2,…,a∣a∣(其中 ∣a∣ 表示序列长度)被称为阶梯序列,当且仅当存在某个下标 i(满足 1≤i≤∣a∣),使得以下条件成立:
a1<a2<⋯<ai−1<ai>ai+1>⋯>a∣a∣−1>a∣a∣.
例如,序列 [1,2,3,2] 和 [4,2] 是阶梯序列,而序列 [3,1,2] 不是。
Sereja 有 m 张写有数字的卡片。他希望从中选出若干张,按顺序摆放在桌面上,构成一个阶梯序列。那么,他最多能在桌面上摆放多少张卡片?
输入格式
The first line contains integer m (1 ≤ m ≤ 105) — 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.
第一行包含一个整数 m(1≤m≤105)—— Sereja 拥有的卡片数量。
第二行包含 m 个整数 bi(1≤bi≤5000)—— Sereja 卡片上的数字。
输出格式
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
输入解题思路,AI测评打分。不知道怎么写?