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 <iostream>
using namespace std;
const int nmax = 2e5 + 5;
int dp[nmax];
int dp2[nmax];
int v[nmax];
int a[nmax];
int bs(int st, int dr, int val, int a[])
{
int x = 0;
while (st <= dr)
{
int mid = (st + dr) / 2;
if (a[mid] >= val)
{
x = mid;
st = mid + 1;
}
else
dr = mid - 1;
}
return x;
}
int main()
{
int n, x, i, l = 0, ans = 0;
cin >> n >> x;
for (i = 1; i <= n; i++)
cin >> v[i];
for (i = n; i; i--)
{
int poz = bs(1, l, v[i], a);
dp[i] = poz + 1;
if (poz == l)
l++;
a[poz + 1] = v[i];
ans = max(ans, dp[i]);
}
l = 0;
for (i = 1; i <= n; i++)
{
int poz = bs(1, l, -(v[i] + x), a);
ans = max(ans, dp[i] + poz - 1);
poz = bs(1, l, -v[i], a);
if (poz == l)
l++;
a[poz + 1] = -v[i];
}
cout << ans;
return 0;
}
# | 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... |