Hey btw @betlista how can you edit an answer? Are you in admin panel or is this because of your Karmas?
Your solution failed for last test case
i edited that case because according to constraints 0 cannot be the tip valueā¦ but if your code was passing previous case then it will pass this tooā¦!! also as @betlista mentioned your code fails on last case add by @betlistaā¦
Because both can deliver just one, the max is when Andy deliver first one for 5 and Bob second one for 8. Bob cannot deliver bothā¦
Your code fails with
2 1 1
6 8
5 6
should be 13, your code returns 12 - CpHHDI - Online C++ Compiler & Debugging Tool - Ideone.com
Are there some good tutorials on state dp ?
as both can deliver only one so there can be two combinations either (bob get 6 and andy get 6 which is equal to 12) or (andy get 5 and bob get 8 which is equal to 13), so 13 is the answer and not 12ā¦!!
For the DP solution should be this part
BobOrders = i - j;
if (BobOrders + 1 <= Y) {
res = max(res, B[i] + dp(i + 1, j + 1));
}
BobOrders = i - j;
if (BobOrders + 1 <= Y) {
res = max(res, B[i] + dp(i + 1, j));
}
@betlista I know my code is failing for cases but what is logically incorrect with my code and the code in the editorial?
Also, when both A[i] and B[i] are same who do we assign to collect the tip?
@betlista please donāt check with what I have submitted, i had better solution but couldnāt submit in time :-/
Your code returns 18 for
3 2 1
7 4 9
7 2 3
correct answer is 20, I kind of do not like cmp
function, but maybe Iām wrongā¦
I think (but didnāt test it yet) that logical problem is in if(v->first<=0 && a<x)
you want handle diff == 0 as last optionā¦
@betlista I guess thatās where the error might be. But, when diff==0 how do we decide who to assign the tip to Andy or Bob?
no it should be 7+4+9
3 2 1
7 4 9
7 2 3
Hope you understoodā¦!!
Thanks . I was doing a silly mistake of interchanging bob and aliceās turns. It got accepted now
yes it should be 28
it should be 28
6+5+9+8
Thanks now I get itā¦