Slope Trick
これがすべて → https://maspypy.com/slope-trick-1-解説編
ABC217H-snuketoon
DP[時刻][現在の位置] = 最小値のDPを考える。これをslope trickに載せると載る。