Amplitude Hackathon Winter '24 Problem 2 - Fog Machine

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 0.25s
Memory limit: 1G

Problem type

Nick has bought a fog machine for Halloween and is helping organize a party where the fog machine will be used to set the mood.

To operate the fog machine, Nick initializes it with a positive integer v_{init}. The fog that comes out of the machine then moves as follows:

  • The initial upward velocity of the fog is v_{init}, and the initial y-coordinate of the fog is 0.
  • While the fog has positive upward velocity, simulate the following steps in order:
    1. Increase the y-coordinate of the fog by the upward velocity.
    2. Decrease the upward velocity by 1.
  • After this point, the fog has reached its maximum height.

There is a smoke detector at y = y_0 that will go off if fog reaches a y-coordinate greater than or equal to that of the smoke detector.

Compute the largest possible value of v_{init} that Nick can initialize the fog machine to without setting off the smoke detector.

Constraints

2 \le y_0 \le 10^5

Input Specification

The first and only line of input contains a positive integer y_0.

Output Specification

Output the maximum possible integer value of v_{init}. It can be shown that, under the constraints of the problem, the answer is always a finite positive integer.

Sample Input 1

3

Sample Output 1

1

Sample Explanation 1

If v_{init} is set to 1, the maximum height the fog reaches is 1. However, if v_{init} is set to 2, the maximum height the fog reaches is 3. Therefore, the answer is 1.

Sample Input 2

4

Sample Output 2

2

Sample Explanation 2

If v_{init} is set to 2, the maximum height the fog reaches is 3. However, if v_{init} is set to 3, the maximum height the fog reaches is 6. Therefore, the answer is 2.


Comments

There are no comments at the moment.