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 ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define lwb lower_bound
#define upb upper_bound
#define TASKNAME "NAME"
void init()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
///freopen(TASKNAME".INP","r",stdin); freopen(TASKNAME".OUT","w",stdout);
}
const int maxN = 1e6+5;
const ll INF = INT_MAX / 2, MOD = 1e9+7, INFLL = 2e18;
const double epsilon = 1e-3;
int n, x, a[maxN], b[maxN], dp[maxN];
int main()
{
init();
cin >> n >> x;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
b[i] = INF;
}
b[0] = -INF;
int res = 0;
for(int i = 1; i <= n; i++)
{
int pos = lower_bound(b, b + n + 1, a[i]) - b;
b[pos] = a[i];
dp[i] = pos;
res = max(res, pos);
}
for(int i = 1; i <= n; i++)
{
b[i] = INF;
}
b[0] = -INF;
for(int i = n; i >= 1; i--)
{
int p = lower_bound(b, b + n + 1, -a[i] + x) - b;
res = max(res, dp[i] + p - 1);
int pos = lower_bound(b, b + n + 1, -a[i]) - b;
b[pos] = -a[i];
}
cout << res;
}
# | 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... |