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;
const int INF = 1e9;
int main() {
int n,x;
cin >>n >> x;
vector<int> v(n);
for(int&i : v) cin >> i;
vector<int> suf(n+1, 0), lds(n+1, -1);
lds[0] = INF;
for(int i = n-1; i >= 0; i--) {
int l = 0, r = n, mo = n;
while(l <= r) {
int mid = (l + r) / 2;
if(lds[mid] > v[i]) {
l = mid+1;
mo = mid;
}
else r = mid-1;
}
//cout << i << ": " << mo << endl;
mo++;
suf[i] = mo;
lds[mo] = v[i];
}
/*for(int i = 0; i < n; i++) cout << suf[i] << ' ';
cout << endl;*/
vector<int> dp(n+1, INF);
dp[0] = -1;
int mo = 0;
for(int i = 0; i < n; i++) {
int a = upper_bound(dp.begin(), dp.end(), v[i] + x) - dp.begin();
/*cout << i << ": ";
for(int i = 0; i <= n; i++) cout << dp[i] << ' ';
cout << endl << a << ", " << suf[i] << endl;*/
mo = max(mo, a-2 + suf[i]);
int j = upper_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
dp[j] = v[i];
}
cout << mo;
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... |