-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_11728
More file actions
94 lines (78 loc) · 2.27 KB
/
BAEKJOON_11728
File metadata and controls
94 lines (78 loc) · 2.27 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.io.*;
import java.util.*;
public class Main {
static int[] result;
static int[] a;
static int[] b;
static int N;
static int M;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
a = new int[N];
b = new int[M];
result = new int[N+M];
st = new StringTokenizer(br.readLine());
for(int i=0; i<N; i++){
a[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine());
for(int i=0; i<M; i++){
b[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(a);
Arrays.sort(b);
//merge(0,N+M-1);
merge();
StringBuilder sb = new StringBuilder();
for(int i=0; i<N+M; i++){
sb.append(result[i]+" ");
}
bw.write(sb.toString());
bw.flush();
bw.close();
}
public static void merge(){
int i=0;
int j=0;
int k=0;
while(i<N && j<M){
if(a[i] <= b[j]){
result[k++]=a[i++];
}else{
result[k++] = b[j++];
}
}
while(i<N)result[k++]=a[i++];
while(j<M)result[k++]=b[j++];
}
/*public static void sort(int start,int end){
if(start==end){
return;
}
int mid = (start+end)/2;
sort(start,mid);
sort(mid+1,end);
merge(start,end);
}
public static void merge(int start,int end){z
int[] b = new int[N+M];
int mid = (start+end) /2;
int i= start, j=mid+1, k=0;
while(i<=mid && j<=end){
if(result[i]<=result[j]){
b[k++] =result[i++];
}else{
b[k++] = result[j++];
}
}
while(i<=mid)b[k++]=result[i++];
while(j<=end)b[k++]=result[j++];
for(int l=start; l<=end; l++){
result[l] = b[l-start];
}
}*/
}