Transistor Repair
InterviewTime limit2sMemory limit1024 MB
Given n leg resistances, find three of them whose sum is A and product is B, or report -1 if none exist.
- Level
Medium4 of 10
- Topics
- Number theory, Hash map, Brute force
- Solved
- No attempts yet
Problem
Papus is teaching Nolik how to repair transistors. A transistor consists of a base and three legs. Each leg has an integer resistance, and the values are known. Two numbers and are written on the base. The transistor works if the sum of the leg resistances is and their product is .
After Papus left, Nolik found a transistor base. To show that he can work on his own, he wants to repair this transistor.
Nolik has legs in his repair kit. He knows how to repair transistors, but choosing the right legs is hard. Help him find three legs that fit this base.
Input
The first line contains three integers , , (, ): the number of legs in the kit, the required sum, and the required product.
The second line contains integers (), the resistances of the legs in the kit.
Output
Print three integers, the resistances of suitable legs. If there are several answers, print any of them. If no answer exists, print -1.