AcWing 1506. 中位数
原题链接
简单
作者:
在月球_0
,
2024-10-09 15:55:04
,
所有人可见
,
阅读 1
#include <iostream>
using namespace std;
const int N = 200100;
int s1[N],s2[N],ret[N * 2];
int m,n;
int main()
{
cin >> n;
for(int i = 0;i < n;i++) {
cin >> s1[i];
}
cin >> m;
for(int i = 0;i < m;i++)
{
cin >> s2[i];
}
int i = 0,j = 0,k = 0;
while(i < n && j < m)
{
if(s1[i] < s2[j]) ret[k++] = s1[i++];
else ret[k++] = s2[j++];
}
while(i < n) ret[k++] = s1[i++];
while(j < m) ret[k++] = s2[j++];
cout << ret[(n + m - 1) / 2] << endl;
return 0;
}