I was trying to solve the KOPC12A problem in SPOJ.
Link to problem: http://www.spoj.com/problems/KOPC12A/
Problem in brief:
Given n buildings, each of different height(number of bricks), with each building having a cost for adding or removing a brick, find the minimum cost to make all the buildings have the same height.
After trying to solve this problem, though in vain, I came across a solution that used ternary search, after sorting the input based on their heights.
I was not able to understand how the cost for equalizing the heights of the buildings becomes unimodal(because ternary search can only be applied on unimodal functions)
This stumped me and I was not able to proceed much further.
Any insights on this is much appreciated.
Thanks-