QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#816612 | #9873. Last Chance: Threads of Despair | xcxc82 | RE | 0ms | 0kb | C++14 | 966b | 2024-12-16 15:33:41 | 2024-12-16 15:33:42 |
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5e5+10;
#define int long long
int a[MAXN],b[MAXN],T,n,m;
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++) cin>>b[i];
sort(a+1,a+n+1),sort(b+1,b+m+1);
int now(0),cnt(0);
for(int i=1;i<=n;i++){
if(a[i]==1) cnt = 1;
else cnt++;
a[i]--;
}
int i = 1,j = 1;
while(1){
if(j>m){
printf("Yes\n");
return;
}
if(a[i]<=now){
now++;
i++;
continue;
}
else if(b[j]<=now){
now++;
j++;
continue;
}
else{
cnt-=(b[j]-now);
if(cnt<0){
printf("No\n");
return;
}
j++;
now++;
}
}
}
signed main(){
cin>>T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 3 2 1 1 4 2 6 3 2 1 1 4 2 7 2 1 100 100 2