Hi all,

I refer you to the following problem.

http://www.codeforces.com/contest/10/problem/E

I tried reading the codes of people who solved the problem, but the codes are pretty cryptic to me. Can someone please enlighten me? Thanks :)

I refer you to the following problem.

http://www.codeforces.com/contest/10/problem/E

I tried reading the codes of people who solved the problem, but the codes are pretty cryptic to me. Can someone please enlighten me? Thanks :)

But is there another way to solve this problem without prior knowledge? It gets a bit daunting if the only way to solve problems is to know some obscure formula beforehand :S

Or maybe, is there an intuitive way from which one can derive the algorithm?

Thanks in advance!