Boris and Berta
InterviewTime limit2sMemory limit512 MB
Given a target distance n and lengths m and c, find non-negative counts of miles and cables whose total length is as close to n as possible.
- Level
Medium4 of 10
- Topics
- Math, Number theory, Brute force, Implementation
- Solved
- No attempts yet
Problem
Boris is making a quest for his sister Berta. One of the tasks is to find a point on the map that is meters north of their house. But it is too easy if is given directly. Boris decided to specify the distance using miles and cables.
He found out that miles vary a lot: from a -meter Chinese mile (called li) up to an -meter Norwegian mile (called mil). A cable length can be anywhere from to meters.
Boris decided to use an -meter mile and a -meter cable. Now he wants to write the -meter distance as " miles and cables" with non-negative integers and as precisely as possible, that is, he wants to minimize . Help him!
Input
Three lines contain an integer each: , the distance to represent, , the chosen length of a mile, and , the chosen length of a cable (; ; ). All values are given in meters.
Output
Print two non-negative integers and , the best approximation of the distance of meters using the chosen mile and cable lengths. If there are multiple best approximations, print any of them.
Hint
The second example test has two correct answers: "1 6" and "3 1".