QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#250604 | #6433. Klee in Solitary Confinement | hhoppitree# | RE | 0ms | 0kb | C++14 | 961b | 2023-11-13 13:55:38 | 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