1029

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zero_1778393206/article/details/87885641
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
	int n, m;
	queue<int> A, B;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a;
		scanf("%d", &a);
		
		A.push(a);
	}
	cin >> m;
	int t;
	if ((n + m) % 2 == 1)
		t = (n + m) / 2 + 1;
	else
		t = (n + m) / 2;
	int c = 0;
	int ans;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d", &b);
		
		B.push(b);
		while (!B.empty())
		{
			if (!A.empty())
			{
				a = A.front();
				b = B.front();
				if (a < b)
					A.pop();
				else
					B.pop();
				c++;
				if (c == t)
				{
					ans = a < b ? a : b;
					break;
				}
			}
			else
			{
				b = B.front();
				B.pop();
				c++;
				if (c == t)
				{
					ans = b;
					break;
				}
			}
		}
		if (c == t)
			break;
	}
	while (c < t)
	{
		c++;
		if (c == t)
			ans = A.front();
		A.pop();
	}
	printf("%d\n", ans);
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/zero_1778393206/article/details/87885641