LCC '23 Contest 3 J2 - Present Unwrapping

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Author:
Problem types

Elsa and Anna are having a competition to see who can unwrap the most presents! Elsa is able to unwrap A presents every minute, and Anna is able to unwrap B presents every minute. However, Anna starts K minutes late because they were too busy practicing for the competition! Since Anna really wants to win this competition, she asks you to find the minimum number of minutes this competition has to last for her to win (unwrap more presents than the other person), or output -1 if it is impossible.

Input Specification

There is one line of input, with space-separated integers A, B, and K.

For all cases, 0 \le A \le 10^6, 0 \le B \le 10^6, 0 \le K \le 10^9.

Note that the answer may not necessarily be able to be stored in a 32-bit integer. You are recommended to use long long in C++ and long in Java.

Output Specification

Output one integer, the minimum number of minutes needed for the competition so that Anna wins this competition, or -1 if it is impossible.

Sample Input 1

2 3 5

Sample Output 1

16

Sample Explanation 1

For the 5 minutes that Anna is missing, Elsa has already unwrapped 10 presents, which means that Anna must unwrap 11 more presents to beat Elsa. Once Anna arrives, for every minute, she will be unwrapping one more present than Elsa, so it takes 11 more minutes to unwrap 11 more presents than Elsa. We see that 5 + 11 = 16 minutes.

Sample Input 2

10 10 1

Sample Output 2

-1

Sample Explanation 2

Anna will never be able to unwrap more presents that Elsa since they unwrap at the same speed and Anna starts late.

Sample Input 3

1 100 99

Sample Output 3

101

Comments

There are no comments at the moment.