Shortest Path on a Line

AtCoder - nikkei2019_2_qual_d