-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathback_11728.cpp
More file actions
52 lines (46 loc) · 879 Bytes
/
back_11728.cpp
File metadata and controls
52 lines (46 loc) · 879 Bytes
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
#include <iostream>
using namespace std;
int arr_n[1000001];
int arr_m[1000001];
int result[2000002];
int pivot_n, pivot_m;
int main()
{
int n,m;
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i =0; i < n; i++)
{
cin >> arr_n[i];
}
for (int i =0; i < m; i++)
{
cin >> arr_m[i];
}
int idx = 0;
while (pivot_n < n && pivot_m < m)
{
if(arr_m[pivot_m] >= arr_n[pivot_n])
{
result[idx++] = arr_n[pivot_n++];
}
else
{
result[idx++] = arr_m[pivot_m++];
}
}
while (pivot_n < n)
{
result[idx++] = arr_n[pivot_n++];
}
while (pivot_m < m)
{
result[idx++] = arr_m[pivot_m++];
}
for (int i =0; i < n+m; i++)
{
cout << result[i] << " ";
}
}