QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485301#7678. The GameyaoyWA 3ms3596kbC++201.7kb2024-07-20 16:03:382024-07-20 16:03:39

Judging History

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

  • [2024-07-20 16:03:39]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3596kb
  • [2024-07-20 16:03:38]
  • 提交

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;
    for (int i = 0; i < r; i++) {
        ans.emplace_back(a[i]);
    }
    for (int j = 0, i = n - m; j < m; j++, i++) {
        for (int v = a[i]; v < b[j]; v++) {
            ans.emplace_back(v);
        }
    }

    std::multiset<int> Sa(a.begin(), a.end()), Sb(b.begin(), b.end());
    for (auto &x : ans) {
        ok &= Sa.contains(x);
        Sa.extract(x);
        Sa.erase(Sa.begin());
        Sa.insert(x + 1);
    }

    ok &= (Sa == Sb);

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

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

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

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: -100
Wrong Answer
time: 3ms
memory: 3516kb

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:

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