QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#806569#9873. Last Chance: Threads of DespairxumoWA 1ms3716kbC++142.3kb2024-12-09 11:52:012024-12-09 11:52:02

Judging History

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

  • [2024-12-09 11:52:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3716kb
  • [2024-12-09 11:52:01]
  • 提交

answer

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

int a[200001]; int b[200001];

bool cmp1(int a, int b) {
    return a > b;
}
bool cmp2(int a, int b) {
    return a < b;
}

void solve() {
    int n, m; cin >> n >> m; int mm = 0;
    for (int i = 1; i <= n; i++)cin >> a[i];
    for (int j = 1; j <= m; j++) { cin >> b[j]; if (b[j] == 1)mm++; }
    
    if (m == 1||mm==m) {
        if (n >= b[1]) {
            cout << "Yes" << endl;
            return;
        }
    }
    
    sort(a + 1, a + n + 1, cmp1);//从大到小
    sort(b + 1, b + m + 1, cmp2);//从小到大
    int ori_bom = 0;
    for (int i = n, j = 1; i >=1 || j <= m;) {
        int i1 = i; int j1 = j;
        if (a[i] == 1)ori_bom++, i--;
        else if (ori_bom >= a[i]&&i>=1)ori_bom++, i--;
        if (b[j] == 1)ori_bom++, j++;
        else if (ori_bom >= b[j]&&j<=m)ori_bom++, j++;
        if (i1 == i && j1 == j) {
            ori_bom = j; break;
        }
    }


    int bom = 0; int cnt = 0; int sit_n = n+1; int sit_m = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == 1) { sit_n = i; break; }
        cnt++; a[i]--;
    }
   
    for (int i = m; i >= 1; i--) {
        if (b[i] == 1) { sit_m = i; break; }
    } 

    if (cnt == n)cnt--;
    else if(b[m]!=1) b[m]--;
     
    //
    for (int i = ori_bom; i <= m; i++) {
        if (cnt >= b[i]) {
            cnt -= b[i] - 1;
            b[i] = 1;
            sit_m++;
        }
        else {
            b[i] -= cnt;
            cnt = 0;
            break;
        }
    }
    if(cnt>0) {
        cout << "Yes" << endl;
        return;
    }
    bom = n - sit_n + 1 + sit_m; 
    sort(b + 1, b + m + 1);
    //if (n == 1 && a[1] == 1)bom = 1;
    for (int i = sit_n - 1, j = sit_m + 1; i >= 1 || j <= m;) {
        int ori_i = i; int ori_j = j;
        if (bom >= a[i]&&i>=1) {
            bom++; i--;
        }
        if (bom >= b[j]&&j<=m) {
            bom++; j++;
            if (j == m + 1) {
                cout << "Yes" << endl;
                return;
            }
        }
        if (ori_i == i && ori_j == j) {
            cout << "No" << endl;
            return;
        }

    }
}

int main() {
    int T; cin >> T;
    while (T--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3716kb

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: 0ms
memory: 3604kb

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: 0ms
memory: 3600kb

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: 0ms
memory: 3652kb

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

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: 1ms
memory: 3688kb

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
No
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
Yes
Yes
No
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Ye...

result:

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