QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#810408#9873. Last Chance: Threads of DespairbexiaoheRE 1ms5636kbC++231.3kb2024-12-11 22:07:262024-12-11 22:07:34

Judging History

你现在查看的是最新测评结果

  • [2024-12-11 22:07:34]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5636kb
  • [2024-12-11 22:07:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define double long double
int t, n, m;

const int N = 5e5 + 10;

int my[N], you[N];

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)cin >> my[i];
	for (int i = 1; i <= m; ++i)cin >> you[i];
	
	sort(my + 1, my + 1 + n);
	sort(you + 1, you + 1 + m);
	
	int idx_my = 1, idx_you = 1, deadline = 1;
	int hurt = 0, judge = 0;
	
	for (int i = 1; i <= n; ++i) {
		if (my[i] == 1) {
			if (judge)continue;
			judge = 1;
			++idx_my;
		}
		--my[i], ++hurt;
	}
	
	if (judge == 0) {
		if (hurt >= you[idx_you]) {
			hurt -= you[idx_you];
			++idx_you;
		}
		else {
			cout << "NO" << endl;
			return;
		}
	}
	
	while (1) {
		while (idx_my <= n && my[idx_my] <= deadline) {
			++idx_my, ++deadline;
		}
		
		if(you[idx_you]<=deadline){
			++deadline;
			++idx_you;
		}
		else if (you[idx_you] <= deadline + hurt) {
			++idx_you;
			hurt -= hurt + deadline - you[idx_you];
		}
		else{
			break;
		}
		
		if (idx_you == m + 1)break;
	}
	
	if (idx_you == m + 1)cout << "YES" << endl;
	else cout << "NO" << endl;
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	//srand(time(0));
	t = 1;
	cin >> t;
	while (t--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5632kb

input:

3
3 2
1 1 4
2 6
3 2
1 1 4
2 7
2 1
100 100
2

output:

YES
NO
YES

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: 0
Accepted
time: 1ms
memory: 5636kb

input:

3
7 1
1 1 1 1 1 1 1
9
5 2
3 4 5 6 7
1 6
5 3
3 4 5 6 7
1 5 7

output:

NO
NO
YES

result:

ok 3 token(s): yes count is 1, no count is 2

Test #3:

score: -100
Runtime Error

input:

4
1 1
1
1
1 1
1
2
1 1
2
1
1 1
2
2

output:


result: