#K34162. Bookshelf Operations

    ID: 25249 Type: Default 1000ms 256MiB

Bookshelf Operations

Bookshelf Operations

You are given N bookshelves each with a specified capacity. You will process Q operations on these shelves. Each shelf can hold books whose total width does not exceed its capacity.

There are two types of operations:

  • Add: Place a book of given width on a specified shelf if there is enough space. Formally, if the current load on shelf \(i\) is \(L_i\) and its capacity is \(C_i\), then the operation is successful if \[ L_i + w \le C_i \] where \(w\) is the width of the book to be added. On success, the output is "Added"; otherwise, output "Not enough space".
  • Remove: Remove a book of given width from a specified shelf. If a book with that width exists on the shelf, remove it and output "Removed"; otherwise, output "Book not found".

Process the operations in order and output the result for each operation.

inputFormat

The input is read from stdin and has the following format:

N Q
C1 C2 ... CN
op1 s1 w1
op2 s2 w2
...
opQ sQ wQ

where:

  • N is the number of shelves.
  • Q is the number of operations.
  • Ci is the capacity of the i-th shelf.
  • Each operation consists of an operation type op (either "Add" or "Remove"), a shelf index s (1-indexed), and a book width w.

outputFormat

For each operation, print a single line to stdout corresponding to the result. The output for each operation is one of:

  • "Added"
  • "Removed"
  • "Not enough space"
  • "Book not found"
## sample
5 4
10 15 20 10 5
Add 1 5
Add 2 8
Remove 1 5
Remove 2 8
Added

Added Removed Removed

</p>