Why I failed orignal constraints?

I recently tried to solve Naive Chef problem in June Challenge and somehow failed to pass orignal constraints test case.
So I checked our submissions of other people and I found something…

Here’s my code->(I scored 20 pts)

Here’s someone else code with 100 pts->

Can you help me out.Please!!I want to know what’s my mistake as both the code’s have exactly same algorithm.

This is because you are setting the array size 105 but n can be as large as 10000 so it must be giving you RE(SIGSEGV) try setting array size to 10005 . then you will get AC. I changed it and got AC see https://www.codechef.com/viewsolution/18875565