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 int
#define F first
#define S second
#define pb push_back
#define md ((b + e) >> 1)
#define lc (ind << 1)
#define rc (lc | 1)
const ll N = 2e5 + 10;
const ll M = 50;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 10;
int n, X, a[N], l[N], r[N], f[N], ans;
int main() {
cin >> n >> X;
int len = 0;
for (int i = 0; i < n; i++){
cin >> a[i];
int p = lower_bound(l, l + len, a[i]) - l;
l[p] = a[i];
len = max(len, p + 1);
f[i] = p + 1;
}
ans = f[n - 1];
len = 0;
for (int i = n - 1; i >= 0; i--){
a[i] *= -1;
int p = upper_bound(r, r + len, a[i] - 1) - r;
ans = max(ans, f[i] + p);
a[i] -= X;
p = lower_bound(r, r + len, a[i]) - r;
r[p] = a[i];
len = max(len, p + 1);
}
cout << ans << '\n';
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... |