QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#806899 | #9873. Last Chance: Threads of Despair | Tom22l | WA | 1ms | 5764kb | C++20 | 1.0kb | 2024-12-09 16:41:33 | 2024-12-09 16:41:35 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int Read(){
int x=0;
char ch=getchar();bool f=0;
while(ch<'0'||ch>'9') if(ch=='-')f=1,ch=getchar(); else if(ch==EOF)return 0; else ch=getchar();
while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return f?-x:x;
}
int a[500005],b[500005];
signed main(){
// freopen(".in","r",stdin);
// freopen("1.in","w",stdout);
int T=Read();
while(T--){
int n=Read(),m=Read();
for(int i=1;i<=n;i++) a[i]=Read();
for(int i=1;i<=m;i++) b[i]=Read();
sort(a+1,a+n+1);
sort(b+1,b+m+1);
int sum=0;
for(int i=1;i<=n;i++) if(a[i]>1) a[i]-=1,sum++;
if(a[1]==1) a[1]-=1,sum++;
int pt=1,pt1=1,cnt=1;
while(1){
while(a[pt]<=cnt-1&&pt<=n) {
// cout<<a[pt]<<' ';
pt++,cnt++;
}
int i=0;
while(b[pt1]-i>cnt-1&&sum>=0) i++,sum--;
if(sum<0) break;
// cout<<b[pt1]<<' '<<i<<endl;
pt1++,cnt++;
if(pt1==m+1)break;
}
if(sum<0) printf("No\n");
else printf("Yes\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5764kb
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: 5764kb
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
Wrong Answer
time: 1ms
memory: 5760kb
input:
4 1 1 1 1 1 1 1 2 1 1 2 1 1 1 2 2
output:
Yes Yes Yes Yes
result:
wrong answer expected NO, found YES [4th token]