355. Inventory Orders
MediumHash MapSimulation
Start with stock levels for items; then process orders item qty. An order is fulfilled only if enough stock exists (then stock decreases). Print the number of fulfilled orders and then each item with its remaining stock in alphabetical order.
Input format
Line 1: n Next n lines: item stock Next line: q Next q lines: item qty
Output format
Line 1: fulfilled count Then: item stock lines
Example 1
Input
2 pen 10 book 3 4 pen 4 book 5 pen 6 ink 1
Output
2 book 3 pen 0
Example 2
Input
1 x 0 1 x 1
Output
0 x 0
Constraints
1 ≤ n, q ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…