#K48837. Store Catalog Manager

    ID: 28509 Type: Default 1000ms 256MiB

Store Catalog Manager

Store Catalog Manager

You are required to implement a store catalog management system that tracks products and their prices. The system should support operations to add or update a product, remove a product, find the price of a product, and determine the cheapest product in the catalog. When multiple products share the same price, the product that was added earlier should be chosen. All operations will be provided via standard input and the results for query operations must be printed to standard output.

The supported commands are:

  • add productName price: Add a new product with the specified price or update the price if it already exists.
  • remove productName: Remove the product from the catalog if it exists.
  • findPrice productName: Print the price of the product, or -1 if the product does not exist.
  • findCheapest: Print the name of the cheapest product. If multiple products share the same lowest price, print the one that was added first. If no products exist, print No products.

Note: The commands are provided one per line. The first line of input contains the integer Q, the number of subsequent commands. Your output should only include responses for the findPrice and findCheapest commands.

inputFormat

The input begins with an integer Q (1 ≤ Q ≤ 10^5) indicating the number of commands. Each of the next Q lines contains one command in one of the following formats:

  1. add productName price
  2. remove productName
  3. findPrice productName
  4. findCheapest

Here, productName is a string (without spaces) and price is an integer.

outputFormat

For each command of type findPrice and findCheapest, print the corresponding output on a new line. For findPrice, print the price of the product if it exists, or -1 otherwise. For findCheapest, print the name of the product with the lowest price (using the order of addition as a tie-breaker) or "No products" if the catalog is empty.## sample

7
add Apple 100
add Banana 50
findPrice Apple
findCheapest
remove Banana
findPrice Banana
findCheapest
100

Banana -1 Apple

</p>