Merge Preferences

How to solve this problem http://www.codechef.com/ALKH2012/problems/MPREF . It would be helpful if somebody provides some insight on solving this one :slight_smile: Thank you in advance :slight_smile:

//