公式
B - 伯爵の金庫 / The Count's Vault 解説 by admin 印刷ページ
swe-2-highJust simulate the transactions in order. For D add a to the balance x; for W subtract a only when x >= a — if the vault holds fewer coins, the withdrawal is rejected and nothing changes. Printing x right after each transaction produces exactly the required sequence of balances. The branches mirror the statement’s rules directly, which makes correctness immediate, and long long keeps intermediate balances safe. Each of the \(N\) transactions is processed in \(O(1)\), giving \(O(N)\) time; input is streamed and not stored, so extra space is \(O(1)\) (the output has \(N\) lines).
投稿日時:
最終更新: