Red button, blue button
InterviewTime limit2sMemory limit512 MB
Given (a,b), reach (c,d) using +1 on both coordinates or doubling both, with the fewest presses, or report -1.
- Level
Medium6 of 10
- Topics
- Math, Greedy, Binary search, Implementation
- Solved
- No attempts yet
Problem
Yeongseon has two integers and . Hyobin has a red button and a blue button.
Pressing the red button increases each of Yeongseon's two integers by 1. Pressing the blue button multiplies each of them by 2.
Hyobin wants to press buttons until becomes . Write a program that finds the smallest number of button presses.
Input
The first line contains four integers , , , . ()
Output
Print the smallest number of button presses that turns into . If that is impossible, print -1.