CF1927C 题解

思路

也是一个贪心题。可以枚举 1k1\sim k 的所有数,若此数在 aabb 中都未出现过,则一定无解了;若只在 aa 中出现而不在 bb 中出现,则说明不能用 bb 里的数字,totbtotb11,只在 bb 中出现同理。结束时,如果 totb>k2totb>\frac k2tota>k2tota>\frac k2,则说明无解了。

代码

# include <bits/stdc++.h>
using namespace std;
int t, n, m, k, a[200005], b[200005], i, j, tot1, tot2;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> t;
	while (t --) {
		cin >> n >> m >> k;
		for (int i = 0; i < n; ++ i)
			cin >> a[i];
		for (int i = 0; i < m; ++ i)
			cin >> b[i];
		sort (a, a + n), sort (b, b + m);
		n = unique (a, a + n) - a, m = unique (b, b + m) - b;
		a[n] = b[m] = i = j = tot1 = tot2 = 0;
		for (int x = 1; x <= k; ++ x)
			if (a[i] != x)
				if (b[j] != x) {
					cout << "NO\n";
					goto there;
				} else
					++ j, ++ tot1;
			else if (b[j] != x)
				++ i, ++ tot2;
			else
				++ i, ++ j;
		k >>= 1;
		if (tot1 > k || tot2 > k)
			cout << "NO\n";
		else
			cout << "YES\n";
there:
		;
	}
	return 0;
}
posted @   sz_jinzikai  阅读(3)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示