#C8375. Shopping Cart System Implementation

    ID: 52350 Type: Default 1000ms 256MiB

Shopping Cart System Implementation

Shopping Cart System Implementation

You are required to implement a shopping cart system. The system must support the following operations:

  • ADD item_id price quantity: Adds an item with the given item_id, price and quantity to the cart. If the item already exists, update its price to the new value and increase its quantity by the specified amount.
  • REMOVE item_id: Removes the item with the given item_id from the cart.
  • UPDATE item_id quantity: Updates the quantity of the given item. If quantity is 0, remove the item.
  • TOTAL: Outputs the total cost of the items in the cart.
  • LIST: Outputs the details of all items in the cart in the order they were added. Each item is printed on a new line in the format: item_id price quantity.

Constraints:

  • $1 \leq q \leq 1000$, where q is the number of operations.
  • $1 \leq item\_id \leq 10^5$.
  • $1 \leq price, quantity \leq 10^6$.

The input will be provided via standard input (stdin) and the required outputs must be printed to standard output (stdout) accordingly.

inputFormat

The first line contains an integer q denoting the number of operations.

Each of the following q lines contains one of the following commands:

  • ADD item_id price quantity
  • REMOVE item_id
  • UPDATE item_id quantity
  • TOTAL
  • LIST

Commands that output a result are TOTAL and LIST.

outputFormat

For each TOTAL command, output a single line containing the total cost of all items. For each LIST command, output the details of items in the cart in separate lines in the format item_id price quantity. The outputs should appear in the same order as the commands in the input.

## sample
9
ADD 1 100 2
ADD 2 50 3
UPDATE 1 5
TOTAL
LIST
REMOVE 2
ADD 3 200 1
TOTAL
LIST
650

1 100 5 2 50 3 700 1 100 5 3 200 1

</p>