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>
// author : a1abay
#define pb push_back
#define all(v) v.begin(), v.end()
#define int ll
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b / (__gcd(a, b)))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int inf = 1e9 + 7;
const int inff = 1e18 + 7;
const int sz = 2e5 + 5;
using namespace std;
int n, x;
int a[sz];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
for(int i = 0; i < n; i++)cin >> a[i];
vector<int> dp(n + 5, inff);
vector<int> l(n + 5, 0), r(n + 5, 0);
for(int i = 0; i < n; i++)
{
int ind = lower_bound(all(dp), a[i]) - dp.begin();
dp[ind] = a[i];
l[i] = ind + 1;
}
int mx = 0;
dp = vector<int>(n + 5, inff);
for(int i = n - 1; i >= 0; i--)
{
int pos = lower_bound(all(dp), -(a[i] - x)) - dp.begin();
int ind = lower_bound(all(dp), -a[i]) - dp.begin();
dp[ind] = -a[i];
mx = max(mx, l[i] + pos);
}
cout << mx;
}
# | 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... |