QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#821109#9873. Last Chance: Threads of DespairvwxyzCompile Error//Python31.3kb2024-12-19 13:19:082024-12-19 13:19:12

Judging History

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

  • [2024-12-19 13:19:12]
  • 评测
  • [2024-12-19 13:19:08]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>

bool solve(int N, int M, std::vector<int>& A, std::vector<int>& B) {
    std::sort(A.begin(), A.end());
    std::sort(B.begin(), B.end());
    int cnt = 0;

    // Adjust A and calculate the count of adjustments
    for (int i = 0; i < N; ++i) {
        if (A[i] > 1 || (i == 0 && A[i] == 1)) {
            cnt++;
            A[i]--;
        }
    }

    int a = 0; // Index pointer for A
    for (int b = 0; b < M; ++b) {
        // Move pointer 'a' while A[a] <= a + b
        while (a < N && A[a] <= a + b) {
            a++;
        }

        // Try to reduce B[b] using the available count
        while (cnt > 0 && a + b < B[b]) {
            B[b]--;
            cnt--;
        }

        // If B[b] cannot be satisfied, return false
        if (a + b < B[b]) {
            return false;
        }
    }
    return true;
}

int main() {
    int T;
    std::cin >> T;

    while (T--) {
        int N, M;
        std::cin >> N >> M;

        std::vector<int> A(N), B(M);
        for (int i = 0; i < N; ++i) std::cin >> A[i];
        for (int i = 0; i < M; ++i) std::cin >> B[i];

        if (solve(N, M, A, B)) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << "No" << std::endl;
        }
    }

    return 0;
}

Details

  File "answer.code", line 5
    bool solve(int N, int M, std::vector<int>& A, std::vector<int>& B) {
         ^^^^^
SyntaxError: invalid syntax