← 返回 meta 的题目列表Library book circulation tracker
类型:online_judge
Your task is to develop a library book circulation tracker.
You are given a sequence of operations that represent activities in a library. Each operation is one of three types: acquisition, checkout, or reclassify. Operations are provided in the following format:
["acquisition", "<book category>", "<quantity>", "<price>"]
The library acquires <quantity> books of <book category>, each valued at <price> for insurance purposes.
["checkout", "<book category>", "<quantity>"]
Patrons borrow <quantity> books of <book category>. If books of the specified category have different insurance values, the least valuable ones should be checked out first. It is guaranteed that the library will always have enough books to fulfill all checkout requests.
["reclassify", "<book category>", "<quantity>", "<original price>", "<new price>"]
The library reclassifies <quantity> books of <book category> to a more valuable edition. It is guaranteed that there are <quantity> books of the specified category with the <original price>.
Your function should calculate the total insurance value of all books checked out after processing the entire sequence of operations. Return an array representing the insurance value of books for each checkout operation.
Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(operations.length) will fit within the execution time limit.
Example
For operations = [ ["acquisition", "fiction", "2", "100"], ["acquisition", "reference", "3", "60"], ["checkout", "fiction", "1"], ["checkout", "reference", "1"], ["reclassify", "reference", "1", "60", "100"], ["checkout", "reference", "1"], ["checkout", "fiction", "1"], ["checkout", "reference", "1"] ], the output should be [100, 60, 60, 100].
Example
Input
[['acquisition', 'fiction', '2', '100'], ['acquisition', 'reference', '3', '60'], ['checkout', 'fiction', '1'], ['checkout', 'reference', '1'], ['reclassify', 'reference', '1', '60', '100'], ['checkout', 'reference', '1'], ['checkout', 'fiction', '1'], ['checkout', 'reference', '1']]
Output
[100, 60, 60, 100]