I was trying to solve the Problem H of the last contest.[problem link]
But I keep on getting Memory Limit Exceeded.Please some one tell me why this is happening .I am bringing here 3 codes. One from which I have learnt which gets accepted and the other two are mine. Please tell me why I get MLE in both cases and why 'B' got passed in test case 5 by making small change in 'A' (only change is made during the last for loop where printing is done) .
case A ->[Link] fails on test case 5
case B ->[Link] fails on test 15
Please clear my concepts so that I dont face these issues in future.Thank You