spoj#HEROARR. Heroes Arrangement

Heroes Arrangement

Please click here to download a PDF version of the contest problems. The problem is problem H in the PDF.