A - 経費の申請 / Expense Claims Editorial by admin Editorial for printing
swe-2-highSolution
Let
\[ S = \sum_{i=1}^{N} A_i \]
be the total amount of the expense claims. Under the company rule, all claims can be submitted if the total is at most \(B\) yen, and they cannot all be submitted if the total exceeds \(B\) yen. Therefore, print Yes if \(S \le B\) and No if \(S > B\).
When \(S = B\), the total does not exceed the limit, so the answer is Yes.
Proof of Correctness
The program reads all values \(A_1, A_2, \ldots, A_N\) and computes their sum. Thus, the computed value equals \(S = \sum_{i=1}^{N} A_i\).
- If \(S \le B\), the total is within the limit, so all \(N\) claims can be submitted. The program prints
Yes. - If \(S > B\), the total exceeds the limit, so not all \(N\) claims can be submitted. The program prints
No.
Therefore, the program always produces the correct output.
Complexity
- Time complexity: \(O(N)\)
- Space complexity: \(O(1)\) in the C++ implementation and \(O(N)\) in the Python implementation because it stores the input tokens
In C++, \(S \le 100 \cdot 10^9 = 10^{11}\), so the sum fits in a long long without overflow.
posted:
last update: