Tree Sustainability

View as PDF

Submit solution

Points: 7
Time limit: 10.0s
Memory limit: 256M

Author:
Problem type

Earth currently has T trees. We estimate that, without human interference, this value increases by P \% each year (rounding down). However, we require wood as a natural resource, so we must cut down N trees each year.

Assume the number of trees increases by P \% before humans cut them down for the year. Determine the maximum value of N such that after K years, there are at least X trees remaining on Earth.

Constraints

1 \le T \le 10^{14}

0 \le P \le 100

1 \le K \le 10^6

The integer X will be given such that there is guaranteed a non-negative answer for N.

Input Specification

The first and only line will contain 4 space-separated integers T, P, K, and X.

Output Specification

Output the maximum value of N such that after K years, there are at least X trees remaining on Earth.

Sample Input 1

100 90 3 1

Sample Output 1

105

Explanation for Sample Output 1

After 1 year: the number of trees increases from 100 to 100 \times (1 + 90 \%) = 190. We cut down 105 trees, leaving us with 85.

After 2 years: the number of trees increases from 85 to \lfloor 85 \times (1 + 90 \%) \rfloor = 161. We cut down 105 trees, leaving us with 56.

After 3 years: the number of trees increases from 56 to \lfloor 56 \times (1 + 90 \%) \rfloor = 106. We cut down 105 trees, leaving us with 1.

Because we have 1 tree remaining after 3 years, 105 is the maximum value for N.

Sample Input 2

100000000000000 100 15 3000000000

Sample Output 2

100003051759392

Explanation for Sample Output 2

Make sure to use 64-bit integers for this problem.


Comments

There are no comments at the moment.