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>
#define int long long
using namespace std;
const int N = 2e5, inf = 2e9+1;
int a[N], best[N];
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,d;
cin >> n >> d;
for (int i=0; i<n; ++i){
cin >> a[i];
}
vector<int> dp(N,inf);
for (int i=0; i<n; ++i){
best[i] = lower_bound(dp.begin(),dp.end(),a[i]+d)-dp.begin()+1;
int pos = lower_bound(dp.begin(),dp.end(),a[i])-dp.begin();
dp[pos] = a[i];
}
dp = vector<int>(N,inf);
int ans = 0;
for (int i=n-1; i>=0; --i){
int lds = lower_bound(dp.begin(),dp.end(),-a[i]-d)-dp.begin();
ans = max(ans,best[i]+lds);
dp[lds] = -a[i]-d;
}
cout << ans;
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... |