QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485290#7678. The GameyaoyCompile Error//C++171.7kb2024-07-20 16:00:402024-07-20 16:00:40

Judging History

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

  • [2024-07-20 16:00:40]
  • 评测
  • [2024-07-20 16:00:40]
  • 提交

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.insert(x + 1);
        Sa.erase(Sa.begin());
    }

    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

answer.code: In function ‘void solve()’:
answer.code:53:18: error: ‘class std::multiset<int>’ has no member named ‘contains’
   53 |         ok &= Sa.contains(x);
      |                  ^~~~~~~~