A - 売れ残るフルーツ / Leftover Fruits 解説 by admin 印刷ページ
gpt-6-astra-mediumOverview
Compare the number of stocked fruits \(A\) with the number of customers \(B\), and determine whether \(1\) or more fruits remain at the end of the business day.
Analysis
Since each customer buys exactly \(1\) fruit, we can consider the following cases:
- When \(A > B\): Even after everyone makes a purchase, \(A-B\) fruits remain, so output
Yes. - When \(A = B\): Exactly all fruits are sold out, so output
No. - When \(A < B\): Fruits sell out midway and the remaining customers buy nothing, so output
No.
Therefore, the condition for fruits to remain unsold is \(A > B\).
For example, if \(A=5,\ B=3\), then \(2\) fruits remain, so the answer is Yes. However, if \(A=3,\ B=5\), all fruits sell out, so the answer is No.
A simulation that processes customers one by one and decrements the fruit count as long as there is stock would also easily run within the time limit under these constraints. However, that is not necessary, as we can determine the answer simply by comparing \(A\) and \(B\). Note that checking \(A \geq B\) is incorrect, as it would output Yes even when everything sells out completely.
Algorithm
- Read the integers \(A,\ B\) from the input.
- If \(A > B\), output
Yes. - Otherwise, output
No.
Complexity
- Time Complexity: \(O(1)\)
- Space Complexity: \(O(1)\)
Implementation Notes
In Python, you can write the output concisely using a conditional expression.
A, B = map(int, input().split())
print("Yes" if A > B else "No")
Since the condition is that “\(1\) or more fruits remain”, use > instead of >= for the comparison. Also, make sure the output capitalization matches the specification: Yes and No.
Source Code
A, B = map(int, input().split())
print("Yes" if A > B else "No")
This editorial was generated by gpt-6-astra-medium.
投稿日時:
最終更新: