I am not discussing the algorithm for any problem and this is a general hint for all problems you are getting a partial score and striving to get 100 points, except Chanllenge problem.
I want to tell everyone a secret which helped me to score 100 points.
I code around 4-5 programs for a problem and i noticed that one of my code was giving CA for last set in second subtask and some other sets from first subtask, and other was giving WA in only last set in second subtask.
Then i just wrote a code that generated random test cases about 100 in each output and tested my both code on same test cases and compared the output (Use ideone for testing be keeping visibility as private), Now thanks for the luck there i got a test case for which m code failed.
I made some corrections and got 100 points.
So i think if i was able to do that then you guys can also do, just write a code to generate random test cases and test your code on these cases and believe me if you dedicate your time wisely you will definitely find the bug…!!
If you don’t know about random functions then check these links or just google :P:
For C : http://stackoverflow.com/questions/822323/how-to-generate-a-random-number-in-c
For Java : http://stackoverflow.com/questions/363681/generating-random-integers-in-a-range-with-java
For Python : (Check Standard Modules tab in this link) http://www.codeskulptor.org/docs.html#tabs-Python
EDIT: While searching more about test case generation i found this link, This has really good explanation: http://www.codechef.com/wiki/test-generation-plan.
Best of Luck…