QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#848965#9574. StripslaonongminCompile Error//C++231.7kb2025-01-09 11:01:192025-01-09 11:01:20

Judging History

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

  • [2025-01-09 11:01:20]
  • 评测
  • [2025-01-09 11:01:19]
  • 提交

answer

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

// 检查是否能覆盖所有红色单元格
bool check(vector<int>& red, vector<int>& black, int k, int w) {
    int n = red.size();
    int m = black.size();
    int i = 0, j = 0;
    int cnt = 0;
    while (i < n) {
        int left = red[i];
        int right = left + k - 1;
        // 检查是否覆盖黑色单元格
        bool flag = true;
        while (j < m && black[j]<right) {
            if (black[j] >= left) {
                flag = false;
                break;
            }
            j++;
        }
        if (flag) {
            cnt++;
            i = upper_bound(red.begin(), red.end(), right)-red.begin();
        } else {
            return false;
        }
    }
    return true;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        int n, m, k, w;
        cin >> n >> m >> k >> w;
        vector<int> red(n);
        for (int i = 0; i < n; i++) {
            cin >> red[i];
        }
        sort(red.begin(), red.end());
        vector<int> black(m);
        for (int i = 0; i < m; i++) {
            cin >> black[i];
        }
        sort(black.begin(), black[i]);
        if (check(red, black, k, w)) {
            int i = 0;
            int cnt = 0;
            int left = red[0];
            cnt++;
            for (int j = 1; j < n; j++) {
                if (red[j]>left + k - 1) {
                    left = red[j];
                    cnt++;
                }
            }
            cout << cnt << endl;
        } else {
            cout << -1 << endl;
        }
    }
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:49:35: error: ‘i’ was not declared in this scope
   49 |         sort(black.begin(), black[i]);
      |                                   ^