# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
741234 | blackslex | Global Warming (CEOI18_glo) | C++17 | 51 ms | 5716 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;
using ll = long long;
const int N = 2e5 + 5;
ll n, k, a[N], b[N], ans;
vector<ll> v, u;
int main() {
scanf("%lld %lld", &n, &k);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (int i = 1; i <= n; i++) {
auto lower = lower_bound(v.begin(), v.end(), a[i]);
if (lower == v.end()) v.emplace_back(a[i]), b[i] = v.size();
else *lower = a[i], b[i] = lower - v.begin();
}
for (int i = n; i >= 1; i--) {
ll idx = lower_bound(u.begin(), u.end(), -a[i] + k) - u.begin();
ans = max(ans, b[i] + idx);
auto lower = lower_bound(u.begin(), u.end(), -a[i]);
if (lower == u.end()) u.emplace_back(-a[i]);
else *lower = -a[i];
}
printf("%lld", 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... |