cook79 Chairs,

somebody tell me why my sol is giving WA. thanks
https://www.codechef.com/viewsolution/12900676

Well firstly you are requesting huge amount of memory inside a function(main function) so the memory will be allocated from the stack and thus it won’t be allocated and may give SIGSEGV fault.To be safe either preceede array declaration with static or make that array global which will ensure that you do not get trapped in abort call.

Secondly try this test case,you will get your mistake
Input:1
10
1110101101
Your code is printing 2 but answer would be 1.Shift the 5th student to 9th position.Since only 1shift is sufficient.Thus,answer would be 1.
Hope it helps…

2 Likes

nice answer.

1 Like

@inovation123 answered your question, you should take a look at the problem setter’s approach.

editorial link:- https://discuss.codechef.com/problems/CHAIRS

1 Like