公式

A - カードを揃える / Collecting Cards 解説 by admin

swe-2-high

For card type \(i\), you need \(A_i\) copies and already own \(B_i\). The shortage is \(A_i - B_i\), but when you already have enough it becomes negative, so the answer is \(\max(A_i - B_i, 0)\). The program reads each pair \((A_i, B_i)\) and immediately prints \(\max(A_i - B_i, 0)\), expressing ‘0 if there is no shortage’ in a single expression without an explicit conditional. Each type is processed once, so the time complexity is \(O(N)\), and since input is handled one pair at a time without being stored, the extra space is \(O(1)\).