Question: #include #include #include using namespace std; int invest ( int N , int D , vector& A ) { vector dp ( N , 1

#include
#include
#include
using namespace std;
int invest(int N, int D, vector& A){
vector dp(N,1);
int maxInvestments =1;
for (int i =0; i < N; i++){
for (int j = i +1; j <= i + D && j < N; j++){
if (A[j]> A[i]){
dp[j]= max(dp[j], dp[i]+1);
maxInvestments = max(maxInvestments, dp[j]);
}
}
}
return maxInvestments;
}
int main(){
int N, D;
cin >> N >> D;
vector A(N);
for (int i =0; i < N; i++){
cin >> A[i];
}
int result = invest(N, D, A);
cout << result << endl;
return 0;
}
output iof this code will be?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!