#C2167. Plot Manager Operations

    ID: 45453 Type: Default 1000ms 256MiB

Plot Manager Operations

Plot Manager Operations

You are required to implement a plot management system that stores rectangular plots. Each plot has a unique identifier and dimensions given by its width and height. The area of a plot is computed as \(\text{area} = \text{width} \times \text{height}\).

The system must support the following operations:

  • add id width height: Add a new plot. If a plot with the same id already exists, output "Error".
  • remove id: Remove an existing plot. If the plot does not exist, output "Error".
  • area id: Output the area of the plot with the given id. If the plot does not exist, output "Error".
  • total: Output the total area of all plots.
  • largest: Output the id of the plot with the largest area. If there are no plots, print "Error".
  • smallest: Output the id of the plot with the smallest area. If there are no plots, print "Error".

All input is read from stdin and all output should be printed to stdout.

inputFormat

The first line of input contains an integer (T) representing the number of operations. Each of the following (T) lines contains a command in one of the following formats:

  • add id width height (e.g. "add 1 3 4")
  • remove id (e.g. "remove 1")
  • area id (e.g. "area 1")
  • total
  • largest
  • smallest

Commands that modify the system (add, remove) do not generate any output unless there is an error.

outputFormat

For each command that requires an output (i.e. area, total, largest, smallest), print the corresponding result on a separate line. If an error occurs (for example, adding a plot with an existing id, removing or querying a non-existent plot, or querying largest/smallest when no plot exists), print "Error".## sample

6
add 1 3 4
area 1
add 2 5 6
total
largest
smallest
12

42 2 1

</p>