# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
148092 | WhipppedCream | Global Warming (CEOI18_glo) | C++17 | 102 ms | 4988 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;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
int n, x;
const int maxn = 2e5+5;
int arr[maxn];
int L[maxn];
int lis[maxn];
int lds[maxn];
int main()
{
scanf("%d %d", &n, &x);
for(int i = 1; i<= n; i++) scanf("%d", arr+i);
int cur = 0;
for(int i = n; i>= 1; i--)
{
int tmp = lower_bound(L, L+cur, -arr[i])-L;
L[tmp] = -arr[i];
cur = max(cur, tmp+1);
lds[i] = tmp+1;
}
cur = 0;
int best = 0;
for(int i = 1; i<= n; i++)
{
best = max(best, lds[i]+(int) (lower_bound(L, L+cur, arr[i]+x)-L));
int tmp = lower_bound(L, L+cur, arr[i])-L;
L[tmp] = arr[i];
cur = max(cur, tmp+1);
lis[i] = cur;
//printf("%d: %d\n", i, best);
}
best = max(best, lis[n]);
printf("%d\n", best);
}
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... |