Approach to solve Posterize from ACM ICPC world finals 2017

What should be the approach to solve problem Posterize from the ACM ICPC world finals 2017.
Link to the problem

//