-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathf.java
More file actions
61 lines (58 loc) · 1.65 KB
/
f.java
File metadata and controls
61 lines (58 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.io.*;
import java.util.*;
public class f{
static int N, a[], occ[];
public static void main(String args[]) throws IOException{
BufferedReader eat = new BufferedReader(new InputStreamReader(System.in));
PrintWriter moo = new PrintWriter(System.out);
N = Integer.parseInt(eat.readLine());
a = new int[N];
occ = new int[200000];
StringTokenizer st = new StringTokenizer(eat.readLine());
for(int i = 0; i < N; i++){
a[i] = Integer.parseInt(st.nextToken()) - 1;
occ[a[i]]++;
}
int mx = 0, l = 0, r = 0;
int cur = 0, prev = 0;
for(int i = 0; i < 200000; i++){
if(occ[i] == 0){
if(cur > mx){
mx = cur;
l = prev;
r = i;
}
prev = i+1;
cur = 0;
}else if(occ[i] == 1){
cur += occ[i];
if(cur > mx){
mx = cur;
l = prev;
r = i+1;
}
prev = i;
cur = occ[i];
}else{
cur += occ[i];
if(cur > mx){
mx = cur;
l = prev;
r = i+1;
}
}
}
moo.println(mx);
for(int i = l; i < r; i++){
moo.print(i+1 + " ");
}
for(int i = r-1; i >= l; i--){
while(--occ[i] > 0){
moo.print(i+1 + " ");
}
}
moo.println();
eat.close();
moo.close();
}
}