Created
June 11, 2022 14:42
-
-
Save kunishi/14f687963680943c1a4cf6e0287231be to your computer and use it in GitHub Desktop.
AtCoder ABC255 Problem C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X, A, D, N = map(int, input().split()) | |
first = min(A, A + D * (N - 1)) | |
last = max(A, A + D * (N - 1)) | |
if X <= first: | |
print(abs(first - X)) | |
elif X >= last: | |
print(abs(X - last)) | |
else: | |
a_min = A + D * ((X - A) // D) | |
a_max = a_min + D | |
print(min(abs(X - a_min), abs(a_max - X))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment