CS Academy Round #38: B. Attack and Speed

,

https://csacademy.com/contest/round-38/task/attack-and-speed/

solution

制約を式に直すと答え$t \in \mathbb{N}$は$A + Xt = S + Y(K - t) \land 0 \le t \le K$。解くだけ。$O(1)$。

implementation

#!/usr/bin/env python3
import random
a, s, k, x, y = map(int, input().split())
num = s - a + k * y
den = x + y
result = -1
if num % den == 0 and 0 <= num // den <= k:
    result = num // den
print(result)