# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259949 | pedroslrey | Global Warming (CEOI18_glo) | C++17 | 85 ms | 3596 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 MAXN = 2e5 + 10;
const int INF = 2e9;
int xs[MAXN];
int dp_lis[MAXN];
int dp_lds[MAXN];
int pos[MAXN];
int main() {
int n, x;
scanf("%d %d", &n, &x);
for (int i = 1; i <= n; ++i)
scanf("%d", &xs[i]);
for (int i = 1; i <= n; ++i)
dp_lis[i] = INF;
int ans = 0;
for (int i = 1; i <= n; ++i) {
int p = lower_bound(dp_lis, dp_lis + n + 1, xs[i]) - dp_lis;
dp_lis[p] = xs[i];
ans = max(ans, p);
pos[i] = p;
}
for(int i = 1; i <= n; ++i)
dp_lds[i] = INF;
dp_lds[0] = -INF;
for (int i = n; i >= 1; --i) {
int idx = lower_bound(dp_lds, dp_lds + n + 1, -xs[i]) - dp_lds - 1;
int p = lower_bound(dp_lds, dp_lds + n + 1, -xs[i] - x) - dp_lds;
dp_lds[p] = -xs[i] - x;
ans = max(ans, pos[i] + idx);
}
printf("%d\n", 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... |