QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250604#6433. Klee in Solitary Confinementhhoppitree#RE 0ms0kbC++14961b2023-11-13 13:55:382023-11-13 13:55:38

Judging History

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

  • [2023-11-13 13:55:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-13 13:55:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5, D = 1e6;

vector<int> M[D << 1];
vector< pair<int, int> > id;

signed main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x);
        M[x + D].push_back(i);
    }
    int res = 0;
    for (int i = -D; i <= D; ++i) {
        id.clear();
        for (auto x : M[i + D]) {
            id.push_back(make_pair(x, -1));
        }
        if (i - m >= -D && i - m <= D) {
            for (auto x : M[i - m + D]) {
                id.push_back(make_pair(x, 1));
            }
        }
        sort(id.begin(), id.end());
        int s = 0, mx = 0;
        for (auto [x, y] : id) {
            s += y;
            if (s < 0) {
                s = 0;
            }
            mx = max(mx, s);
        }
        res = max(res, mx + (int)M[i + D].size());
    }
    printf("%d\n", res);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

5 2
2 2 4 4 4

output:


result: