Official
A - 羊の数え直し / Recounting the Sheep Editorial by admin
swe-2-highEditorial
In the morning there are \(A\) sheep in the first flock and \(B\) sheep in the second flock, so the total is \(A + B\) sheep. In the evening all sheep are gathered and counted as \(C\) sheep. The number of sheep has neither increased nor decreased if and only if \(A + B = C\).
Therefore, we output Yes if \(A + B = C\), and No otherwise.
Proof of correctness
- If \(A + B = C\): the morning total \(A + B\) equals the evening count \(C\), so no sheep was added or lost. The algorithm prints
Yes, which is correct. - If \(A + B \neq C\): the totals differ, so the number of sheep changed. The algorithm prints
No, which is correct.
Complexity
- Time: \(O(1)\)
- Space: \(O(1)\)