WA IN SUBSGM

What is wrong with the following code http://ideone.com/0UVmG0 for the problem http://www.codechef.com/LTIME10/problems/SUBSGM.

As per the subtask 1 (i.e. 1 <= N <= 100, 1 <= M <= 1000) is considered, it should have passed. For rest, I know it would give TLE but why it is giving WA for subtask 1 also.

@damn_me: please ask your question on the problem editorial: http://discuss.codechef.com/tags/ltime10