A poor man
had p cats and c
dogs, which he took with him from place to place. One day he arrived at a deep
river, which not even the bravest dog would have swum. On the bank of the river
our man found a boat, but unfortunately it only fit k
animals.
So our man decided to cross the river several times, until all the animals arrive to the other side.
The problem is not so simple because, due to a legendary happening, if the animals remain unattended on a bank and the number of dogs is larger than the number of cats, the dogs will lethally attack the cats.
Task
Write a program that determines the minimum number of crossings our man has to make in order to transport all the animals safely to the other bank.
Input Data
Input file cd.in contains a single line with three positive integers separated by a space, p c k, with the meaning from the task.
Output Data
Output file cd.out will contain a single line with the minimum number of crossings necessary.
Restrictions and Mentions
cd.in | cd.out | Explanation |
5 7 3 |
9 |
A solution with a minimum number of crossings can be:
|
Time limit: 0.4 seconds/test
prof. Emanuela Cerchez
"Grigore Moisil" Iaşi IT High School
Contact:emanuela.cerchez@gmail.com