Created
June 18, 2019 02:58
-
-
Save 2minchul/11e4620aaa4d4c1913e54ea71b15b083 to your computer and use it in GitHub Desktop.
A solution for: https://www.acmicpc.net/problem/16283
This file contains hidden or 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
| # 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