# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968703 | blackslex | Global Warming (CEOI18_glo) | C++17 | 47 ms | 4704 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;
int n, d;
int main() {
scanf("%d %d", &n, &d);
vector<int> t(n), dp(n), dp2(n);
for (auto &e: t) scanf("%d", &e);
vector<int> c;
for (int i = 0; i < n; i++) {
auto lower = lower_bound(c.begin(), c.end(), t[i]);
if (lower == c.end()) c.emplace_back(t[i]), dp[i] = c.size();
else *lower = t[i], dp[i] = lower - c.begin() + 1;
}
int ans = c.size(); c.clear();
for (int i = n - 1; i >= 0; i--) {
auto lower = lower_bound(c.begin(), c.end(), -t[i]);
dp2[i] = lower_bound(c.begin(), c.end(), -t[i] + d) - c.begin();
if (lower == c.end()) c.emplace_back(-t[i]);
else *lower = -t[i];
}
for (int i = 1; i < n; i++) ans = max(ans, dp[i - 1] + dp2[i]);
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... |