-
Notifications
You must be signed in to change notification settings - Fork 708
Expand file tree
/
Copy pathmerge.cpp
More file actions
70 lines (53 loc) · 1.29 KB
/
merge.cpp
File metadata and controls
70 lines (53 loc) · 1.29 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
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define endl "\n"
#define ll long long
#define PI 3.1415926535
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
using namespace std;
ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
void merge (int a[], int b[], int n, int m)
{
int x=n-1;
int y=0;
while(x>=0 && y<m)
{
if(a[x] > b[y]){
swap(a[x], b[y]);
x--;
y++;
}else{
break;
}
}
sort(a, a+n);
sort(b, b+m);
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int n,m;
cin>>n>>m;
int a[n], b[n];
for(int i=0; i<n; i++)
cin>>a[i];
for(int i=0; i<m; i++)
cin>>b[i];
merge(a,b,n,m);
for(int i=0; i<n; i++)
printf("%d ", a[i]);
for(int i=0; i<m; i++)
printf("%d ", b[i]);
cout<<endl;
}