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 MAX = 2e5 + 5;
int n, x, arr[MAX];
int memo[MAX][2];
int rek(int pos, bool drop){
if(pos == 0) return 1;
if(memo[pos][drop] > 0) return memo[pos][drop];
int maxi = 0;
for(int i = 0; i < pos; i++){
if(arr[pos] > arr[i]) maxi = max(maxi, rek(i, drop));
if(arr[i] - arr[pos] < x && drop) maxi = max(maxi, rek(i, 0));
}
return memo[pos][drop] = maxi + 1;
}
int main()
{
cin >> n >> x;
for(int i = 0; i < n; i++) cin >> arr[i];
int maxi = 0;
for(int i = 0; i < n; i++) maxi = max(maxi, rek(i, 1));
cout << maxi;
/*for(int i = 0; i < n; i++){
printf("%d\n drop left: %d\n no drop left: %d\n", i, rek(i, 1), rek(i, 0));
}*/
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... |