Codeforce Round #223 Div2 B
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:
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 ≤ 105) — the number of Sereja's cards. The second line contains m integers bi (1 ≤ bi ≤ 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.
5
1 2 3 4 5
5
5 4 3 2 1
6
1 1 2 2 3 3
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 }
浙公网安备 33010602011771号