Official

A - 経費の申請 / Expense Claims Editorial by admin Editorial for printing

swe-2-high

Editorial

Whether all expenses can be submitted depends only on the total amount. Compute \(S = A_1 + A_2 + \cdots + A_N\) and print Yes if \(S \leq B\), otherwise No.

The program accumulates each \(A_i\) into total as it reads it, then checks total <= b once at the end. Since \(A_i\) can be up to \(10^9\) and \(N \leq 100\), the sum can reach \(10^{11}\), and \(B\) can also be as large as \(10^{11}\). These exceed 32-bit integer range, so long long is required.

Complexity

Time complexity is \(O(N)\). Extra space is \(O(1)\) since the input is processed on the fly (storing the array would still only cost \(O(N)\)).

posted:
last update: