Sherlock and Cost - Hackerrank

Can somebody provide me with how to construct the optimal array, or construct the dp table/array for sum?

Problem link : Sherlock And Cost

I am able to partially solve it for specific test cases, but still I am failing for ~60% of other type of test cases.

My code- ideone link (Tell if its not visible/accessible, I will paste my code here then.)

EDIT- Updated link. Please have a look, if needed.

Nope, code not visible.

“This Sherlock and Cost submission belongs to Vijju123”

So it can’t be seen :stuck_out_tongue:

Don’t just paste it here. Better to share it using ideone.com

okay, noted.

The key point here is to choose number between 1 and b[i].But for maximizing the required answer we have to choose either 1 or b[i].Your Implementation is wrong i guess…
Take this case n=2 and elements of array are 99 and 89. Your code gives the output as 88 but output should be 98. Hope you got this :slight_smile:

I did realized the key point.

“Your Implementation is wrong i guess…”

Dude, I lol’d so hard at that XD. I mean, OF COURSE my implementation is wrong, that’s why I am getting WA lmao XD. (No offence, but that thing cracked me up haha XD).

I want to know what went wrong, why and how to correct that. So I need more explanation, thanks :slight_smile:

I was unable to understand your code as you are missing some cases. So I found it hard to debug.But I found a case that was failing,thinking that might help you. :slight_smile:

I know these test cases :p. (That’s why I mentioned my code fails at 60% of the type of test cases possible XD.). But yeah, thanks for feedback dear :slight_smile:

1 Like
//