Chef ans Tetris

please help me to figure out what is wrong with my solution https://www.codechef.com/viewsolution/10824494

1 Like

This happened with me as well.

It is happening because of n=1.

Just a separate if statement for n=1 needs to be added.

my wrong solution

my correct solution

your corrected solution

2 Likes

Please tell me what’s wrong with this : https://www.codechef.com/viewsolution/10763381

Thanks in advance.

@anujdubey1996
Try this testcase

1
4
5 3 3 4 
10 2 6 7

your code outputs -1, but the answer is 10.

1 Like

Please tell me what’s wrong with this https://www.codechef.com/viewsolution/10824928

@akshay29

The order of those if statements in your code is wrong, b[j-1] has to be given preference because it can’t be added to a[j+1].

Therefore if statements having b[j-1] should be placed above others, and a few permutations can be tried :wink:

I just changed the order of if statements, in your code and got AC.

your corrected solution

1 Like

Can you please tell the problem in this solution?

@palashshah

Again the order of if and else if statements is wrong.

your corrected solution

1 Like

@prakhariitd

can you again explain why the ordering is important here… i am not getting the logic behind this

thank you @prakhariitd

Welcome :slight_smile: