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, d;
vector <int> arr;
int current_max;
int solve(int indx, int maxi){
vector <int> options;
int max_options;
options.resize(d+5);
int condition;
int the_max = 0;
if(indx == n) {
if(arr[indx] > maxi) return 1;
else return 0;
}
for(int i = 1; i<= d; i++){
if(indx + i >= n) break;
else{
if(arr[indx+i] > maxi){
condition = 1;
the_max = arr[indx+i];
}
else {
the_max = maxi;
condition = 0;
}
options[i] = solve(indx + i, the_max) + condition;
}
}
max_options = 0;
for(int i = 1; i <=d; i++){
if(options[i] > max_options) max_options = options[i];
}
return max_options;
}
int main(){
cin >> n >> d;
arr.resize(n);
for(int i = 0; i<n; i++){
cin >> arr[i];
}
for(int i = 0; i<n; i++){
//cout << "for indx: " << i << ": " << solve(i, arr[i]) << endl;
if(solve(i, arr[i]) > current_max) {
current_max = solve(i, arr[i]);
}
}
cout << current_max + 1;
}
# | 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... |