# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
741230 | blackslex | Global Warming (CEOI18_glo) | C++17 | 46 ms | 4560 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k, a[N], b[N], c[N], ans;
vector<int> v, u;
int main() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
auto lower = lower_bound(v.begin(), v.end(), a[i] - k);
if (lower == v.end()) b[i] = v.size(), v.emplace_back(a[i] - k);
else *lower = a[i] - k, b[i] = lower - v.begin();
}
for (int i = n; i >= 1; i--) {
auto lower = lower_bound(u.begin(), u.end(), a[i]);
if (lower == u.end()) c[i] = u.size(), u.emplace_back(a[i]);
else *lower = a[i], c[i] = lower - u.begin();
}
for (int i = 1; i <= n; i++) ans = max(ans, b[i] + c[i] + 1);
printf("%d", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |