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;
int n, x;
int main(){
cin >> n >> x;
int V[n];
int dp[n][2];
for(int i = 0; i < n; ++i) cin >> V[i];
for(int i = 0; i < n; ++i){
dp[i][0] = dp[i][1] = 1;
}
int ans = 1;
for(int i = 1; i < n; ++i){
for(int j = 0; j < i; ++j){
if(V[j] < V[i]){
dp[i][0] = max(dp[i][0], dp[j][0]+1);
dp[i][1] = max(dp[i][1], dp[j][1]+1);
ans = max(ans, dp[i][0]);
ans = max(ans, dp[i][1]);
}
if(V[j]-x < V[i]){
dp[i][1] = max(dp[i][1], dp[j][0]+1);
ans = max(ans, dp[i][1]);
}
}
}
cout << ans << endl;
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... |