A - 落葉の掃除 / Fallen Leaves Cleaning Editorial by admin
gpt-6-astra-mediumOverview
The total number of fallen leaves is \(A \times B\). We simulate cleaning up to \(C\) leaves per day and determine whether all leaves can be cleaned within \(D\) days.
Analysis
To finish cleaning as early as possible, we should clean the maximum possible amount of up to \(C\) remaining leaves each day.
Therefore, let leaves be the remaining number of leaves, initialized to \(A \times B\). Each day we clean, we subtract \(C\) from leaves, and once the remaining count becomes \(0\) or less, we determine that all leaves have been cleaned.
For example, when \(A=3,\ B=5,\ C=4,\ D=4\), there are \(15\) leaves in total. The remaining count changes as follows:
- After 1 day: \(11\)
- After 2 days: \(7\)
- After 3 days: \(3\)
- After 4 days: \(-1\)
In reality, only the remaining \(3\) leaves are cleaned on the last day, but the code uniformly subtracts \(C\). For this reason, a negative remaining count is also treated as completion.
Since \(D \leq 1000\) in this problem, a naive day-by-day simulation is well within the time limit. However, note that if the completion condition is set to “the remainder is exactly \(0\),” it will result in a Wrong Answer for the example above.
Additionally, since the maximum number of leaves that can be cleaned in \(D\) days is \(C \times D\), one can also directly check whether \(A \times B \leq C \times D\). The code presented here performs the day-by-day simulation.
Algorithm
- Read \(A,B,C,D\).
- Set the remaining leaves
leavesto \(A \times B\). - While both of the following conditions are met, subtract \(C\) from
leavesand increment the elapsed days by 1:- The elapsed days is less than \(D\).
leavesis greater than \(0\).
- If
leavesis \(0\) or less, outputYes; otherwise, outputNo.
If leaves still remain after \(D\) days despite cleaning the maximum possible amount every day, cleaning any less would not finish either, so this check gives the correct answer.
Complexity
- Time complexity: \(O(D)\). The loop runs at most \(D\) times.
- Space complexity: \(O(1)\). Only a fixed number of variables are used.
Implementation Notes
The condition to check completion should be
leaves <= 0, notleaves == 0.Once cleaning is completed midway, further simulation is unnecessary. The loop terminates early due to the condition
leaves > 0.By initializing
dayto \(0\) and using the conditionday < d, the cleaning is performed at most \(D\) times.As specified, the output is case-sensitive: output either
YesorNo.Source Code
// 問題文から独立に実装: 1 日ずつ掃除して残りが 0 以下になるか
#include <iostream>
int main() {
long long a, b, c, d; std::cin >> a >> b >> c >> d;
long long leaves = a * b;
for (int day = 0; day < d && leaves > 0; ++day) leaves -= c;
std::cout << (leaves <= 0 ? "Yes" : "No") << std::endl;
}
This editorial was generated by gpt-6-astra-medium.