QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#729312#9574. Stripsucup-team1264#Compile Error//C++201.6kb2024-11-09 16:52:142024-11-09 16:52:14

Judging History

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

  • [2024-11-09 16:52:14]
  • 评测
  • [2024-11-09 16:52:14]
  • 提交

answer

#include <iostream>
#include <vector>
#include <set>
using namespace std;

void solve() {
    int n, m, k, w;
    cin >> n >> m >> k >> w;
    vector<pair<int, int>> a;
    a.reserve(n + m + 2);
    a.push_back({ 0, 0 });
    a.push_back({ w + 1, 0 });
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        a.push_back({ x, 1 });
    }
    for (int i = 0; i < m; i++) {
        int x; cin >> x;
        a.push_back({ x, 0 });
    }
    sort(a.begin(), a.end());

    bool sat = true;
    vector<int> ans;

    auto solve = [&](int i, int j, int lb, int rb) {
        int rc = lb;
        vector<int> tmp;
        for (int p = i; p < j; p++) {
            if (a[p].first > rc) {
                tmp.push_back(a[p].first);
                rc = a[p].first + k - 1;
            }
        }
        int m = tmp.size(), ls = rb;
        for (int p = m - 1; p >= 0; p--) {
            tmp[p] = min(tmp[p], ls - k);
            ls = tmp[p];
        }
        if (ls <= lb) sat = false;
        for (int x : tmp) ans.push_back(x);
        };

    int t = n + m + 2;
    for (int i = 0, j; i < t; i = j) {
        for (j = i; j < t && a[j].second == a[i].second; j++);
        if (a[i].second == 0) continue;
        int lb = a[i - 1].first, rb = a[j].first;
        solve(i, j, lb, rb);
    }

    if (!sat) cout << -1 << "\n";
    else {
        cout << ans.size() << "\n";
        for (int x : ans) cout << x << " ";
        cout << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t; cin >> t;
    while (t--) solve();
}

詳細信息

answer.code: In function ‘void solve()’:
answer.code:21:5: error: ‘sort’ was not declared in this scope; did you mean ‘short’?
   21 |     sort(a.begin(), a.end());
      |     ^~~~
      |     short