Hide and Seek 5
Time limit0.25sMemory limit512 MB
Subin walks (X±1) or teleports (2X) each second while her sibling's position grows by an accelerating walk; find the earliest second she can land exactly on the sibling, or -1.
- Level
Medium7 of 10
- Topics
- BFS, Graph, Math, Implementation
- Solved
- No attempts yet
Problem
Subin is playing hide and seek with her younger sibling. Subin is currently at point , and her sibling is at point .
Subin can walk or teleport. When Subin is at position , walking moves her to or after 1 second, and teleporting moves her to after 1 second.
The sibling only walks. The sibling moves every second, and the distance covered accelerates. Each move covers 1 more than the previous move. That is, the sibling's initial position is , after 1 second it is , after 2 seconds it is , and after 3 seconds it is .
Given the positions of Subin and her sibling, write a program that finds how many seconds it takes at the earliest for Subin to find her sibling. The position where Subin finds her sibling must be an integer coordinate, and Subin cannot move to a coordinate less than or greater than .
Input
The first line gives Subin's position and her sibling's position . and are integers.
Output
Print the earliest time in seconds for Subin to find her sibling. If Subin cannot find her sibling, or the position where she finds it exceeds , print .