I have been stuck in this problem 478C - Table Decorations for ages now, i cannot understand the editorial (http://codeforces.me/blog/entry/18619), why does this work and also i have problem in understanding the binary search approach (https://abitofcs.blogspot.in/2014/10/a-bit-of-cf-codeforces-round-273-div-2.html), somebody please help me by providing a detailed proof!!