QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#816612#9873. Last Chance: Threads of Despairxcxc82RE 0ms0kbC++14966b2024-12-16 15:33:412024-12-16 15:33:42

Judging History

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

  • [2024-12-16 15:33:42]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-12-16 15:33:41]
  • 提交

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

output:


result: