QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#809116#9873. Last Chance: Threads of DespairprovenWA 0ms3564kbC++201.4kb2024-12-11 11:51:542024-12-11 11:51:54

Judging History

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

  • [2024-12-11 11:51:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3564kb
  • [2024-12-11 11:51:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1), b(m + 1);
    for(int i = 1;i <= n;i++) cin >> a[i];
    for(int i = 1;i <= m;i++) cin >> b[i];
    sort(a.begin() + 1, a.end());
    sort(b.begin() + 1, b.end());
    int a1 = 0, b1 = 0;
    for(int i = 1;i <= n;i++) {
        a1 += (a[i] == 1);
    }
    for(int i = 1;i <= m;i++) {
        b1 += (b[i] == 1);
    }
    int cnt = (a1 != 0);
    for(int i = 1;i <= n;i++) {
        if(a[i] > 1) cnt++, a[i]--;
    }
    int now = a1, flag = 0;
    if(b1) {
        if(!a1) cnt--;
        now += b1;
        flag = 1;
    }
    int k = 1;
    for(int i = 1;i <= m;i++) {
        if(b[i] == 1) {
            continue;
        }
        while(k <= n && a[k] <= now) {
            k++;
            now++;
        }
        int num = b[i] - now;
        if(num <= 0) now++, flag = 1;
        else {
            if(cnt < num) {
                cout << "No" << endl;
                return;
            }
            now++;
            cnt -= num;
            flag = 1;
        }
    }
    cout << "Yes" << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3564kb

input:

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

output:

Yes
Yes
Yes

result:

wrong answer expected NO, found YES [2nd token]