Skip to content

Instantly share code, notes, and snippets.

@2minchul
Created June 18, 2019 02:58
Show Gist options
  • Select an option

  • Save 2minchul/11e4620aaa4d4c1913e54ea71b15b083 to your computer and use it in GitHub Desktop.

Select an option

Save 2minchul/11e4620aaa4d4c1913e54ea71b15b083 to your computer and use it in GitHub Desktop.
# https://www.acmicpc.net/problem/16283
def solution(a, b, n, w):
no_result = '-1'
if a == b:
if a + b == w and n == 2:
return '1 1'
else:
return no_result
x, x_mod = divmod(w - b * n, a - b)
if x_mod:
return no_result
y = n - x
if x < 1 or y < 1:
return no_result
return ' '.join((str(x), str(y)))
def test_solution():
assert solution(3, 4, 9, 32) == '4 5'
assert solution(3, 4, 8, 32) == '-1'
assert solution(100, 100, 2, 200) == '1 1'
assert solution(1, 3, 4, 5) == '-1'
assert solution(2, 2, 3, 4) == '-1'
assert solution(1, 3, 4, 7) == '-1'
if __name__ == '__main__':
input_list = input().split()
print(solution(*map(int, input_list)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment