I am not able to figure out whats the problem in my code RPLB, I have tried all the possible test cases and edge conditions…What is the case I am missing?? Here is my code:-
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
int tc=1;
while(t–){
int n,k;
cin >> n >> k;
int a[n],ans[n];
for(int i=0; i<n; i++){
cin >> a[i];
}
memset(ans,0, sizeof (ans));
for(int i=n-1; i>=0; i--){
int max= 0;
for(int j=i+2; j<n; j++){
if(max<ans[j] && ans[j]+a[i]<=k){
max= ans[j];
}
}
if(max+a[i]<=k)
ans[i]=max+a[i];
}
int anss=0;
for(int i=0; i<n; i++){
if(anss<ans[i]){
anss=ans[i];
}
}
cout << "Scenario #" << tc << ": " << anss << endl;
tc++;
}
return 0;
}