...a dynamic programming approach for problem "hacker rank...
So, dp[i][0] is the maximum possible cost of the array A[1..i] if we choose to put A[i-1]=1. And similarly, dp[i][1] will store the best cost we can get of the array A[1..i] if we put A[i-1]=B[i]. So the answer will be max(dp[n][0] , dp[n][1]). W...