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;
#define endl '\n'
const int N = 2e5 + 5;
int dp[N][2];
void solve(){
ll n,x;
cin>>n>>x;
vector<ll> v(n);
for(int i=0;i<n;i++) cin>>v[i];
for(int i=n-1;i>=0;i--){
for(int j=0;j<2;j++){
for(int k=i+1;k<n;k++){
if(v[k] > v[i]){
dp[i][j] = max(dp[i][j] , dp[k][j] + 1);
}
}
if(!j){
for(int k=i+1;k<n;k++){
if(v[k] > v[i]-x){
dp[i][j] = max(dp[i][j] , dp[k][1] + 1);
}
}
}
}
}
int ans = 0;
for(int i=0;i<n;i++){
ans = max(ans, dp[i][0] + 1);
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
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... |