A - 落葉の掃除 / Fallen Leaves Cleaning 解説 by admin
gpt-6-astra-mediumOverview
We determine whether all leaves can be cleaned by comparing the total number of fallen leaves in the garden with the maximum number of leaves that can be cleaned in \(D\) days.
Analysis
There are \(A\) trees, and \(B\) leaves fall from each tree, so the total number of fallen leaves is \(A \times B\).
On the other hand, since up to \(C\) leaves can be cleaned per day, at most \(C \times D\) leaves can be cleaned in \(D\) days. Therefore, the condition to clean all the leaves is:
\(A \times B \leq C \times D\)
If the total number of fallen leaves is less than or equal to the maximum number that can be cleaned, all leaves can be cleaned within \(D\) days by cleaning as much as possible each day. Conversely, if it exceeds the maximum number, it is impossible to clean them all.
For example, when \(A=3,\ B=4,\ C=5,\ D=3\), the number of fallen leaves is \(12\) and the maximum number that can be cleaned is \(15\), so the answer is Yes.
Simulating the process by decreasing the number of fallen leaves day by day would easily run within the time limit under these constraints. However, simply comparing the products requires no loops. In addition, computing the required number of days via integer division as \(A \times B \div C\) risks producing a wrong answer due to truncation (rounding down). Comparing the products avoids the need for such rounding logic.
Algorithm
- Read \(A, B, C, D\).
- Calculate the total number of fallen leaves \(A \times B\) and the maximum number of cleanable leaves \(C \times D\).
- If \(A \times B \leq C \times D\), output
Yes; otherwise, outputNo.
Complexity
- Time Complexity: \(O(1)\)
- Space Complexity: \(O(1)\)
Implementation Notes
If the total number of fallen leaves equals the maximum number of leaves that can be cleaned, all of them can still be cleaned. Use
<=instead of<for the comparison.The output strings are case-sensitive; output
YesorNoexactly as specified.Source Code
# 問題文から独立に実装
a, b, c, d = map(int, input().split())
print("Yes" if a * b <= c * d else "No")
This editorial was generated by gpt-6-astra-medium.