Can someone please give me some hints to solve this problem. Thanks in Advance!!
Need idea: Tried to solve it using bitmask + segment tree, but getting WA. Any idea about how to solve this problem efficiently?
This problem is from ACM Southwestern European Regional Contest, Paris 2003
This is a beautiful problem that I solved today. The idea is very interesting and the implementation can be a little difficult.