Farm
InterviewTime limit0.1sMemory limit512 MB
Given feed rates a and b, animal count n, and total feed w, find the sheep and goat counts, or print -1 if the answer is missing or not unique.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Sangbae, the owner of a farm, raises sheep and goats together. He keeps at least one sheep and at least one goat. The sheep and the goats eat the same feed: one sheep eats exactly a grams of feed per day, and one goat eats exactly b grams per day.
Every morning Sangbae checks how many sheep and how many goats he has. Because the animals wander around, counting them exactly is not easy. Instead, he plans to find the two counts from the total number of animals and the total amount of feed the animals ate during the previous day.
Given that the total number of animals Sangbae counted is n and that the total amount of feed eaten during the previous day is w grams, write a program that finds how many sheep and how many goats there are.
Input
Input is read from standard input. The first line contains four integers a, b, n, w on one line. 1 ≤ a ≤ 1,000, 1 ≤ b ≤ 1,000, 2 ≤ n ≤ 1,000, 2 ≤ w ≤ 1,000,000.
Output
Output is written to standard output. On the first line, print the number of sheep and the number of goats. If there is more than one possible answer, or if there is no possible answer, print -1.