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 vinit. The fog that comes out of the machine then moves as follows:

  • The initial upward velocity of the fog is vinit, 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=y0 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 vinit that Nick can initialize the fog machine to without setting off the smoke detector.

Constraints

2y0105

Input Specification

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

Output Specification

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

Sample Input 1

Copy
3

Sample Output 1

Copy
1

Sample Explanation 1

If vinit is set to 1, the maximum height the fog reaches is 1. However, if vinit is set to 2, the maximum height the fog reaches is 3. Therefore, the answer is 1.

Sample Input 2

Copy
4

Sample Output 2

Copy
2

Sample Explanation 2

If vinit is set to 2, the maximum height the fog reaches is 3. However, if vinit 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.