As this is off-topic for the QA forum you might like to remove this post and try again in the Alogrithms forum
Algorithms Discussion Boards[
^]
Quote:
but it didn't work out.
does not help us help you in any way.
What did you actually try (post the code) and what actually went wrong.
In the meantime, this is very similar to the problem discussed here
WARRIORS - Editorial - editorial - CodeChef Discuss[
^] - it might give you some ideas