Official

A - 売れ残るフルーツ / Leftover Fruits Editorial by admin

gpt-6-astra-medium

Overview

We compare the number of stocked fruits \(A\) with the number of customers \(B\) to determine whether at least \(1\) fruit remains at the end of business.

Analysis

Since each customer buys exactly \(1\) fruit, we can consider the following cases:

  • When \(A > B\): Even after everyone buys a fruit, \(A-B\) fruits will remain, so output Yes.
  • When \(A = B\): All fruits are completely sold out, so output No.
  • When \(A < B\): The fruits sell out along the way, 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; if \(A=3,\ B=5\), all fruits are sold out, so the answer is No.

Simulating the process by serving customers one by one and decreasing the inventory would easily run within the time limit under these constraints. However, such a simulation is unnecessary, and the problem can be solved simply by comparing the two values. Also, be careful: if you use the condition \(A \geq B\), it will incorrectly output Yes for \(A=B\), where the fruits are completely sold out.

Algorithm

  1. Read the integers \(A,\ B\).
  2. If \(A > B\), output Yes.
  3. Otherwise, output No.

Complexity

  • Time complexity: \(O(1)\)
  • Space complexity: \(O(1)\)

Implementation Notes

Use map(int, input().split()) to read the two space-separated integers.

Using a conditional expression in Python, the check and output can be written in a single line:

print("Yes" if a > b else "No")

Ensure that the output matches Yes or No exactly as specified, including uppercase and lowercase letters.

Source Code

# 問題文から独立に実装
a, b = map(int, input().split())
print("Yes" if a > b else "No")

This editorial was generated by gpt-6-astra-medium.