#C6748. Resource Allocation Simulation
Resource Allocation Simulation
Resource Allocation Simulation
You are required to simulate a resource allocation system. There are two types of events: CHECKOUT
and RETURN
.
How it works:
- When a
CHECKOUT
event occurs, if the resource is not already checked out, assign it to the specified user. - If a
RETURN
event occurs, and the resource is currently held by the specified user, mark it as returned. - If a
RETURN
event is invoked for a resource not held by the user, ignore the event. - If a
CHECKOUT
event is invoked for a resource that is already checked out, ignore the event.
After processing all events, output a JSON object (printed as a string) where the keys are user IDs and the values are arrays (sorted in lexicographical order) of resource IDs that are currently checked out by that user. If there are no resources allocated, output an empty JSON object {}.
Note on formulas: There are no mathematical formulas in this problem.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains an integer N indicating the number of events.
- Each of the next N lines contains three space-separated strings: an event type (either
CHECKOUT
orRETURN
), a user ID, and a resource ID.
outputFormat
Output via standard output (stdout) a JSON object (as a string) whose keys are user IDs and values are arrays of resource IDs (sorted in lexicographical order) that remain checked out. If no resources are allocated, output {}.
## sample0
{}