QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#811332#9873. Last Chance: Threads of DespairNana7#WA 1ms5760kbC++141.3kb2024-12-12 18:03:162024-12-12 18:03:17

Judging History

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

  • [2024-12-12 18:03:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5760kb
  • [2024-12-12 18:03:16]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<algorithm>
#define I inline
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

const double PI = 3.14159265358;
const double eps = 1e-8;
const int N = 500100;

int n,m,k,a[N],b[N];
multiset< pii > pq;

I void solve() {
	cin>>n>>m; pq.clear();
	for(int i=1;i<=n;++i) cin>>a[i];
	for(int j=1;j<=m;++j) cin>>b[j];
	
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	
	int sa=1,sb=1,bz=0,at=0;
	for(int i=1;i<=n;++i) {
		if(a[i]==1) {
			sa++;
			bz++;
		} else break;
	}
	for(int i=1;i<=n;++i) at+=(a[i]>1);
	if(a[1]==1) at++;
	
	while(sb<=m) {
		if(b[sb]<=bz) {
			bz++;
			sb++;
			while(sa<=n&&a[sa]-1<=bz) {
				bz++;
				sa++;
			}
		} else {
			while(at&&b[sb]>bz) {
				b[sb]--;
				at--;
			} 
			if(b[sb]<=bz) {
				sb++;
				bz++;
				while(sa<=n&&a[sa]-1<=bz) {
					bz++;
					sa++;
				}
			} else {
				break;
			}
		} 
	}

	
	if(sb==m+1) {
		cout<< "Yes"<<endl ;
	} else {
		cout<<"No"<<endl;
	}
}  
signed main()
{
	int T; cin>>T;
	while(T--) {
		solve();
	}	
}
/*
 3
 3 2
 1 1 4
 2 6
 3 2
 1 1 4
 2 7
 2 1
 100 100
 2

 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
 
=
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5760kb

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: 0
Accepted
time: 1ms
memory: 5752kb

input:

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

output:

Yes
Yes
Yes
No

result:

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

Test #4:

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

input:

18
1 2
1
1 1
1 2
1
2 1
1 2
1
1 3
1 2
1
2 2
1 2
1
3 2
1 2
1
3 3
1 2
2
1 1
1 2
2
1 2
1 2
2
1 3
1 2
2
2 2
1 2
2
2 3
1 2
2
3 3
1 2
3
1 1
1 2
3
1 2
1 2
3
1 3
1 2
3
2 2
1 2
3
3 2
1 2
3
3 3

output:

Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
No
No
Yes
No
No
No
No
No

result:

ok 18 token(s): yes count is 7, no count is 11

Test #5:

score: 0
Accepted
time: 0ms
memory: 5740kb

input:

18
2 1
1 1
1
2 1
1 1
2
2 1
1 1
3
2 1
1 2
1
2 1
2 1
2
2 1
2 1
3
2 1
1 3
1
2 1
1 3
2
2 1
3 1
3
2 1
2 2
1
2 1
2 2
2
2 1
2 2
3
2 1
2 3
1
2 1
3 2
2
2 1
2 3
3
2 1
3 3
1
2 1
3 3
2
2 1
3 3
3

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No

result:

ok 18 token(s): yes count is 15, no count is 3

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 5736kb

input:

525
2 3
1 1
1 1 1
2 3
1 1
1 2 1
2 3
1 1
1 3 1
2 3
1 1
1 4 1
2 3
1 1
5 1 1
2 3
1 1
2 2 1
2 3
1 1
3 1 2
2 3
1 1
1 2 4
2 3
1 1
2 1 5
2 3
1 1
3 3 1
2 3
1 1
4 3 1
2 3
1 1
3 5 1
2 3
1 1
4 4 1
2 3
1 1
4 5 1
2 3
1 1
1 5 5
2 3
1 1
2 2 2
2 3
1 1
2 3 2
2 3
1 1
2 2 4
2 3
1 1
2 5 2
2 3
1 1
3 2 3
2 3
1 1
3 2 4
2 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
No
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
No
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes...

result:

wrong answer expected YES, found NO [59th token]