No.846 Medals
Problem Statement
A mathematics contest was held in the country of yuki, and all participants received distinct ranks. In this contest, medals are awarded to some of the participants as follows.
- Let $N$ be the total number of participants.
- The top $\lceil N/P\rceil$ participants are awarded gold medals.
- Among the top $\lceil N/Q\rceil$ participants, everyone who has not yet been awarded a medal is awarded a silver medal.
- Among the top $\lceil N/R\rceil$ participants, everyone who has not yet been awarded a medal is awarded a bronze medal.
Here, for a real number $x$, $\lceil x\rceil$ denotes the smallest integer greater than or equal to $x$ (that is, the value of $x$ rounded up to an integer).
Rusk does not know the total number of participants $N$, but he heard in the news that the numbers of people awarded gold, silver, and bronze medals are $A$, $B$, and $C$, respectively.
Determine whether there exists a possible value of the total number of participants $N$, and if so, find the minimum and maximum values of $N$.
Input
$P\ Q\ R$ $A\ B\ C$
- $2\leq R < Q < P \leq 10^9$
- $0\leq A, B, C\leq 10^9$
- $A > 0$
- All input values are integers.
Output
If no possible value of the total number of participants $N$ exists, output $-1$ on its own. If one exists, output the minimum and maximum values in this order, separated by a space.
Sample
Sample 1
Input
12 4 2 9 16 25
Output
99 100
For example, if there are $100$ participants:
- First, the top $\lceil 100/12\rceil =9$ participants are awarded gold medals.
- Next, among the top $\lceil 100/4\rceil =25$ participants, the $16$ who have not been awarded a gold medal are awarded silver medals.
- Next, among the top $\lceil 100/2\rceil =50$ participants, the $25$ who have not been awarded a gold or silver medal are awarded bronze medals.
Sample 2
Input
6 3 2 3 3 4
Output
-1
It is impossible for the numbers of gold, silver, and bronze medalists to be $3$, $3$, and $4$, respectively. The news is false.
Sample 3
Input
7 5 3 1 0 0
Output
1 3
Sample 4
Input
789123456 456789123 123456789 157 114 729
Output
123333332212 123456789000
Note that the answer may not fit in a $32$-bit integer type.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
chocorusk
zunda1st