-
Notifications
You must be signed in to change notification settings - Fork 3
/
CCC17S2.java
52 lines (51 loc) · 1.72 KB
/
CCC17S2.java
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/**
* CCC '17 S2 - High Tide, Low Tide
* Question type: Implementation
* 10/15 on DMOJ
* Question URL: https://dmoj.ca/problem/ccc17s2
* @author Tommy Pang
*/
public class CCC17S2 {
static StringTokenizer st;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static Integer [] tides, high, low;
public static void main(String[] args) throws IOException{
int N = Integer.parseInt(br.readLine());
tides = new Integer[N]; low = new Integer[N/2];
List<Integer> high = new ArrayList<>();
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
tides[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(tides);
if (N%2==0){
for (int i = 0; i < N/2; i++) {
low[i] = tides[i];
}
for (int i = N/2; i < N; i++) {
high.add(tides[i]);
}
Arrays.sort(low, Collections.reverseOrder());
for (int i = 0; i < N/2; i++) {
System.out.print(low[i] + " " + high.get(i) + " ");
}
}
else {
for (int i = 0; i < N/2; i++) {
low[i] = tides[i];
}
for (int i = N/2; i < N; i++) {
high.add(tides[i]);
}
Arrays.sort(low, Collections.reverseOrder());
for (int i = 0; i < N/2; i++) {
System.out.print(low[i] + " " + high.get(i) + " ");
}
System.out.print(high.get(N/2) + "\n");
}
}
}