Full Score: 100 Input file name: in.txt or standard input stream Output file name:…
- User
Full Score: 100 Input file name: in.txt or standard input stream Output file name: out.txt or standard output stream
Time limit: 1 с
Physical memory limit: 256M
Stack size limit: 256M
Petya and lanterns time limit per test: 1 second memory limit per test: 256 megabytes
Petya lives on an avenue, which is a coordinate line. Petya's house is at point x and his school is at point y. Since Petya lives in the north, it is still dark outside when he walks to school from home. The winter is long and there is little sunshine, so at each point of the avenue whose coordinate is divisible by k, there is a street lamp. For example, if k = 3, then there are lanterns at points -6, -3, 0, 3, 6, and so on in both directions.
Each lantern shines left and right by l. For example, if the lantern is at point 2, and l = 4, then the lantern illuminates the line segment from -2 to 6.
Petya does not like to walk along the dark parts of the avenue. He wants to develop a plan to install additional streetlights (with the same parameter l) so that the path from home to school will be fully illuminated. Help Petya and determine the minimum number of streetlights to be added so that the path from the house to the school is fully illuminated.
The path from the house to the school is called illuminated if every point of the path is illuminated by at least one lantern.
Input data The first line contains 4 integers x, y, k, l (-10^9 <= x, y <= 10^9, 1 <= k, l <= 10^9).
Output data In a single line print one integer - the answer to the problem.
Evaluation system Solutions that work correctly for -10^3 < x, y ≤ 10^3 , will receive at least 45 points. Solutions that work correctly for positive x, y will receive at least 45 points.
Example Input data: -8 10 3 1
Output data: 6
Note One of the possible optimal arrangements of lanterns in the example test is -8, -4.5, -1, 1.5, 4, 8. The lantern at point -8 covers the segment [-9, -7]. The lantern at point -6 covers [-7, -5]. The lantern at point -4.5 covers [-5.5, -3.5]. The lantern at -3 covers |-4, -2]. The lantern at -1 covers [-2, 0]. The lantern at point 0 covers [-1, 1]. The lantern at point 1.5 covers [0.5, 2.5]. The lantern at point 3 covers [2,4]. The lantern at point 4 covers [3,5]. The lantern at point 6 covers [5, 7]. The lantern at point 8 covers [7, 9]. The lantern at point 9 covers [8, 10].
Thus every point of the segment [-8, 10] is covered by at least one lantern. For example, point -5.5 is covered by two lanterns at once: in points -6, -4.5.
Translated with DeepL.com (free version)
- Assistant
To solve this problem efficiently, we need to find a way to calculate the minimum number of additional street lamps without iterating over potentially billions of existing lamps. Here’s how we can approach it:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.