Giving tle i have used dp

code- https://ide.codingblocks.com/s/335121

hey @anubhavb11 your solvedp function is incorrect . i have corrected your function. check it out

if(n < 0){

    return 0;

}

if(dp[n][s]!=-1){

    return dp[n][s];

}

if (wt[n] > s) { 



    dp[n][s] = solvedp(n-1, wt, pr, s , dp); 

    return dp[n][s]; 

} 

else { 

    dp[n][s] = max( 

        pr[n] + solvedp(n-1 , wt , pr , s - wt[n],dp), solvedp(n-1 , wt, pr, s , dp)); 

    return dp[n][s]; 

}

whats wrong with my code that code you have send I can see it on gfg

@anubhavb11 hey look you have call solvedp function and then you are calling another function solve in it which will lead to tle as both of them are recursive function so remove the solve function from code and do in one single function i.e solvedp function.