Codeforces Round #577D. Treasure Hunting(二分+DP)

NoSuchKey