Auctions R Us

Time limit1sMemory limit128 MB

Problem

You are opening a new auction business. To keep out buyers who win an auction and then back out, every bidder must deposit funds with you before they are allowed to bid on any item. The moment a bidder wins an auction, the amount they bid is deducted from their account balance in that very second.

Write a program that simulates a single day of auctions. Several items are auctioned off, and each item has a reserve (minimum) price that must be met. Each bidder has a deposited balance, and every winning bid is paid out of that balance. Your program tracks every auction during the day and reports the result of each one.

Guarantees

  • No two items have the same end time.
  • No two bids have the same bid time.
  • No price, bid amount, or account balance is negative.
  • Bidder numbers are unique among bidders and item numbers are unique among items, but a bidder may share a number with an item. Numbers are not necessarily assigned in sequence.

Winning rule

An auction is won by the highest bid that satisfies all of the following:

  • It was placed no later than the second the auction ends.
  • Its amount is greater than or equal to the item's minimum price.
  • At the instant the auction ends, the bidder's remaining account balance is at least the bid amount.

Because a winning bid is deducted the instant its auction ends, process the auctions in order of their end times: a bidder who wins an earlier auction may no longer have enough balance to win a later one.

Input

The input has three parts: the items available for bidding, the registered bidders, and the bids placed during the day.

Items

  • A line with the number of items, i.
  • i lines, one per item: item_number minimum_price end_time
    • item_number is a non-negative integer.
    • minimum_price is given to the penny (0.01).
    • end_time is in 24-hour HH:MM:SS format, where HH is 00–23, MM is 00–59, and SS is 00–59.

Bidders

  • A line with the number of registered bidders, j.
  • j lines, one per bidder: bidder_number account_balance
    • bidder_number is a non-negative integer.
    • account_balance is given to the penny (0.01).

Bids

  • A line with the number of bids received, k.
  • k lines, one per bid: item_number bidder_number bid_amount bid_time
    • Every field uses the same format described above.

Output

Print one line for each item, in order of the item's auction end time.

For an item that has a winning bid, print:

Item <item_number> Bidder <bidder_number> Price <winning_bid>

For an item with no winning bid, print:

Item <item_number> Reserve not met.

Amounts are printed to the penny (for example, 27.00).