Ternary Search problem

Problem link: Problem - 1244E - Codeforces
How to solve it with ternary search? :slightly_smiling_face: