• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #223 Div2 B

B. Sereja and Stairs
time limit per test 1 second
 

Sereja loves integer sequences very much. He especially likes stairs.

Sequence a1, a2, ..., 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:

a1 < a2 < ... < ai - 1 < ai > ai + 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?

Input

The first line contains integer m (1 ≤ m ≤ 105) — the number of Sereja's cards. The second line contains m integers bi (1 ≤ bi ≤ 5000) — the numbers on the Sereja's cards.

Output

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

Sample test(s)
Input
5 
1 2 3 4 5
Output
5 
5 4 3 2 1
Input
6 
1 1 2 2 3 3
Output
5 
1 2 3 2 1
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <stack>
 6 #include <queue>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 #define maxn 1000005
12 int n, m;
13 int b, w, x, c, y;
14 int a[maxn], vis[maxn];
15 int main(){
16     scanf("%d", &n);
17     w = 0;
18     for (int i = 0; i < n; i++){
19         scanf("%d", &a[i]);
20         vis[a[i]]++;
21         w = max(w, a[i]);
22     }
23     int t = 0;
24     for (int i = 0; i < 5005; i++){
25         t += min(2, vis[i]);
26     }
27     if (vis[w] >= 2)t--;
28     printf("%d\n", t);
29     for (int i = 0; i < 5005; i++){
30         if (vis[i])printf("%d ", i);
31     }
32     for (int i = 5005; i >= 0; i--){
33         if (vis[i] >= 2 && i != w)printf("%d ", i);
34     }
35     return 0;
36 }
View Code
posted @ 2014-01-19 15:48  HaibaraAi  阅读(138)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3