QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485351#7678. The GameyaoyWA 23ms3884kbC++202.0kb2024-07-20 16:47:222024-07-20 16:47:22

Judging History

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

  • [2024-07-20 16:47:22]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:3884kb
  • [2024-07-20 16:47:22]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    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];
    }

    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());

    bool ok = true;
    int dif = 0;
    for (int i = n - 1, j = m - 1; j >= 0; j--, i--) {
        ok &= (a[i] <= b[j]);
        dif += b[j] - a[i];
    }

    if (!ok || dif > n - m) {
        std::cout << -1 << "\n";
        return;
    }

    int r = n - m - dif;
    for (int i = 0; i < r; i++) {
        ok &= (a[i] + 1 <= b[0]);
    }
    if (!ok) {
        std::cout << -1 << "\n";
        return;
    }

    std::vector<int> ans;

    auto output = [&]() {
        std::cout << ans.size() << "\n";
        for (int i = 0; i < ans.size(); i++) {
            std::cout << ans[i] << " \n"[i == ans.size() - 1];
        }
    };

    std::multiset<int> Sb(b.begin(), b.end());
    auto check = [&]() -> bool {
        bool OK = true;
        std::multiset<int> Sa(a.begin(), a.end());
        for (auto &x : ans) {
            OK &= Sa.contains(x);
            Sa.extract(x);
            Sa.insert(x + 1);
            Sa.erase(Sa.begin());
        }
        OK &= (Sa == Sb);
        return OK;
    };

    std::multiset<int> S(a.begin(), a.begin() + n - m);
    for (int i = 0; i < r; i++) {
        int x = *S.begin();
        S.erase(S.begin());
        S.insert(x + 1);
        S.erase(S.begin());
        ans.emplace_back(x);
    }
    for (int j = 0, i = n - m; j < m; j++, i++) {
        for (int v = a[i]; v < b[j]; v++) {
            ans.emplace_back(v);
        }
    }

    if (check()) {
        output();
        return;
    }

    std::cout << -1 << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
5 3
1 2 2 3 3
2 3 4
4 2
1 2 2 4
2 4
5 2
2 3 3 4 4
5 5
6 1
1 1 1 1 1 1
4
4 2
1 1 1 2
2 2
4 1
1 1 1 1
2

output:

2
1 3
-1
3
2 4 4
5
1 1 1 2 3
2
1 1
-1

result:

ok ok (6 test cases)

Test #2:

score: 0
Accepted
time: 3ms
memory: 3624kb

input:

7056
4 3
1 1 1 1
1 1 1
4 3
1 1 1 1
1 1 2
4 3
1 1 1 1
1 1 3
4 3
1 1 1 1
1 1 4
4 3
1 1 1 1
1 1 5
4 3
1 1 1 1
1 1 6
4 3
1 1 1 1
1 2 2
4 3
1 1 1 1
1 2 3
4 3
1 1 1 1
1 2 4
4 3
1 1 1 1
1 2 5
4 3
1 1 1 1
1 2 6
4 3
1 1 1 1
1 3 3
4 3
1 1 1 1
1 3 4
4 3
1 1 1 1
1 3 5
4 3
1 1 1 1
1 3 6
4 3
1 1 1 1
1 4 4
4 3
1 1...

output:

-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2
-1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok ok (7056 test cases)

Test #3:

score: 0
Accepted
time: 3ms
memory: 3592kb

input:

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1
-1
-1
-1
-1
3
1 1 2
3
1 1 3
3
1 3 4
3
3 4 5
-1
-1
-1
-1
-1
3
1 1 2
3
1 1 4
3
1 4 5
3
4 5 6
-1
-1
-1
-1
-1
3
1 1 2
3
1 1 5
3
1 5 6
3
5 6 7
-1
-1
-1
-1
-1
3
1 1 2
3
1 1 6
3
1 6 7
-1
-1
-1
-1
-1
-1
3
1 1 2
3
1 1 7
-1
-1
-1
-1
-1
-1
-1
3...

result:

ok ok (2640 test cases)

Test #5:

score: 0
Accepted
time: 6ms
memory: 3884kb

input:

14112
5 3
1 1 1 1 1
1 1 1
5 3
1 1 1 1 1
1 1 2
5 3
1 1 1 1 1
1 1 3
5 3
1 1 1 1 1
1 1 4
5 3
1 1 1 1 1
1 1 5
5 3
1 1 1 1 1
1 1 6
5 3
1 1 1 1 1
1 2 2
5 3
1 1 1 1 1
1 2 3
5 3
1 1 1 1 1
1 2 4
5 3
1 1 1 1 1
1 2 5
5 3
1 1 1 1 1
1 2 6
5 3
1 1 1 1 1
1 3 3
5 3
1 1 1 1 1
1 3 4
5 3
1 1 1 1 1
1 3 5
5 3
1 1 1 1 1
...

output:

-1
-1
2
1 2
-1
-1
-1
2
1 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
2 3
-1
-1
-1
2
1 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
1 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok ok (14112 test cases)

Test #6:

score: 0
Accepted
time: 3ms
memory: 3592kb

input:

5292
5 2
1 1 1 1 1
1 1
5 2
1 1 1 1 1
1 2
5 2
1 1 1 1 1
1 3
5 2
1 1 1 1 1
1 4
5 2
1 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-1
4
1 1 2 3
4
1 1 2 4
4
1 1 4 5
4
1 4 5 6
-1
-1
-1
-1
4
1 1 2 3
4
1 1 2 5
4
1 1 5 6
-1
-1
-1
-1
-1
4
1 1 2 3
4
1 1 2 6
-1
-1
-1
-1
-1
-1
4
1 1 2 3
-1
-1
...

result:

ok ok (3234 test cases)

Test #8:

score: 0
Accepted
time: 4ms
memory: 3652kb

input:

8820
5 4
1 1 1 1 1
1 1 1 1
5 4
1 1 1 1 1
1 1 1 2
5 4
1 1 1 1 1
1 1 1 3
5 4
1 1 1 1 1
1 1 1 4
5 4
1 1 1 1 1
1 1 1 5
5 4
1 1 1 1 1
1 1 2 2
5 4
1 1 1 1 1
1 1 2 3
5 4
1 1 1 1 1
1 1 2 4
5 4
1 1 1 1 1
1 1 2 5
5 4
1 1 1 1 1
1 1 3 3
5 4
1 1 1 1 1
1 1 3 4
5 4
1 1 1 1 1
1 1 3 5
5 4
1 1 1 1 1
1 1 4 4
5 4
1 1 1...

output:

-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok ok (8820 test cases)

Test #9:

score: 0
Accepted
time: 13ms
memory: 3648kb

input:

26460
6 5
1 1 1 1 1 1
1 1 1 1 1
6 5
1 1 1 1 1 1
1 1 1 1 2
6 5
1 1 1 1 1 1
1 1 1 1 3
6 5
1 1 1 1 1 1
1 1 1 1 4
6 5
1 1 1 1 1 1
1 1 1 1 5
6 5
1 1 1 1 1 1
1 1 1 2 2
6 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1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok ok (50000 test cases)

Test #11:

score: 0
Accepted
time: 12ms
memory: 3848kb

input:

25872
6 3
1 1 1 1 1 1
1 1 1
6 3
1 1 1 1 1 1
1 1 2
6 3
1 1 1 1 1 1
1 1 3
6 3
1 1 1 1 1 1
1 1 4
6 3
1 1 1 1 1 1
1 1 5
6 3
1 1 1 1 1 1
1 1 6
6 3
1 1 1 1 1 1
1 2 2
6 3
1 1 1 1 1 1
1 2 3
6 3
1 1 1 1 1 1
1 2 4
6 3
1 1 1 1 1 1
1 2 5
6 3
1 1 1 1 1 1
1 2 6
6 3
1 1 1 1 1 1
1 3 3
6 3
1 1 1 1 1 1
1 3 4
6 3
1 1 ...

output:

-1
-1
-1
3
1 2 3
-1
-1
-1
3
1 1 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
1 1 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
2 3 4
-1
-1
-1
3
1 2 3
-1
-1
3
1 2 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
1 1 1
3
1 1 2
-1
-1
-1
-1
-1
-1
-1
-1...

result:

ok ok (25872 test cases)

Test #12:

score: 0
Accepted
time: 13ms
memory: 3692kb

input:

25872
6 2
1 1 1 1 1 1
1 1
6 2
1 1 1 1 1 1
1 2
6 2
1 1 1 1 1 1
1 3
6 2
1 1 1 1 1 1
1 4
6 2
1 1 1 1 1 1
1 5
6 2
1 1 1 1 1 1
1 6
6 2
1 1 1 1 1 1
1 7
6 2
1 1 1 1 1 1
2 2
6 2
1 1 1 1 1 1
2 3
6 2
1 1 1 1 1 1
2 4
6 2
1 1 1 1 1 1
2 5
6 2
1 1 1 1 1 1
2 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

result:

wrong answer Jury has answer but participant has not (test case 3)