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;
typedef long long ll;
const int N = 222222;
ll a[N], l[N], d[N];
pair<int, int> change[N];
int main()
{
int n, x;
cin >> n >> x;
for(int i = 1; i <= n; i ++)
cin >> a[i];
int lis = 0;
for(int i = 0; i <= n; i ++)
l[i] = 1e9;
int ans = 0;
for(int i = 1; i <= n; i ++)
{
int id = lower_bound(l + 1, l + n + 1, a[i]) - l;
change[i] = {id, l[id]};
l[id] = a[i];
ans = max(ans, id);
}
int lds = 0;
for(int i = n; i >= 1; i --)
{
int id = lower_bound(d + 1, d + n + 1, a[i] + x, greater<int>()) - d;
d[id] = a[i] + x;
l[change[i].first] = change[i].second;
// cout << i << ' ' << id << '\n';
// for(int j = 0; j <= lds - 1; j ++)
// cout << d[j] << ' ';
// cout << '\n';
int it = lower_bound(l + 1, l + n + 1, a[i] + x) - l-1;
ans = max(ans, it + id);
}
cout << ans;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:16:6: warning: unused variable 'lis' [-Wunused-variable]
int lis = 0;
^~~
glo.cpp:27:6: warning: unused variable 'lds' [-Wunused-variable]
int lds = 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... |