Quote:
0 down vote
LOL
Quote:
This question was recently ask in a contest which is now over
These contest are especially designed to challenge your skills, so you got the answer: You are unable to solve it.
Quote:
I tried to solve it by brute force but it give TLE
brute force is never the solution of these contests, never. Nota: there is brute force and brute force, the brute force of a seasoned programmer can be in no way similar the a beginner brute force, so we have no idea what you did and how bad is your solution.
Quote:
anybody please explain the proper approach for this is very helpful
Just giving you a full blowup solution will never help you to learn anything. Because the necessary explanations would be hours just explain you how the solution works. The reason of our solutions is years of practice and of data structures / algorithm studying. We can't teach you those years of experience even in matter of days.
So you would endup with a magic solution that you can't understand.
The only useful help is an advice: take a sheet of paper and a pencil and solve by hand, the analyze how you solved the problem, how you did choices, it is basically your algorithm, because you didn't used brute force (testing every possible steps combinations), you did better.