Official

A - 二人の水筒 / Two Water Bottles Editorial by admin Editorial for printing

swe-2-high

Solution

Takahashi’s bottle contains \(A\) milliliters and Aoki’s bottle contains \(B\) milliliters, so together they have \(A + B\) milliliters of water.

Since the trip requires at least \(C\) milliliters in total, we only need to check whether \(A + B \geq C\). If it holds, print Yes; otherwise print No.

Proof of Correctness

The required output is determined solely by whether the combined amount of water in the two bottles is at least the required amount \(C\). The total amount of water they carry is \(A + B\) milliliters, and this being at least \(C\) is equivalent to the condition \(A + B \geq C\). Therefore a program that directly evaluates this condition and prints Yes / No exactly satisfies the problem’s requirement.

On the boundary: the condition is “at least \(C\) milliliters”, so when \(A + B = C\) the answer must still be Yes. Since we use the >= comparison, this case is correctly answered Yes.

Complexity

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

We read three integers and perform one addition and one comparison, so the program runs in constant time and constant space.

posted:
last update: