cook79 Chairs,

somebody tell me why my sol is giving WA. thanks

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
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…


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

editorial link:-

1 Like

nice answer.

1 Like