Yet Another Minimization Problem

CodeForces - 868F