Kattis Problem - Saving For Retirement
题意
Bob 从 B B B 岁开始直到 B r B_r Br 岁退休,每年存 B s B_s Bs 元钱。Alice 现在 A A A 岁,每年可以存 A s A_s As 元钱。求 Alice 在多少岁时退休存的钱比 Bob 退休时存的钱多。
分析
Bob 总共存的钱是 B s ∗ ( B r − B ) B_s * (B_r - B) Bs∗(Br−B),所以 Alice 需要存 B s ∗ ( B r − B ) / A s + 1 B_s * (B_r - B) / A_s + 1 Bs∗(Br−B)/As+1 年。
代码
public static void solve() throws IOException {
int B = nextInt();
int r = nextInt();
int b = nextInt();
int A = nextInt();
int a = nextInt();
int sum = b * (r - B);
pw.println(A + sum / a + 1);
}