cho.sh
Notes
Loading...

Transaction Limit Checking

Time limit

1s

Memory limit

128 MB

Problem

A bank wants to prevent customers from accidentally sending much more money than they intended. Each transaction is a request to transfer money from one account to another.

There are two kinds of transactions:

  • An inter-account transfer (IAT) transfers money between two accounts owned by the same customer.
  • A payment transfers money to an account owned by someone else.

For each transaction kind, every customer specifies two limits:

  • the maximum instruction limit, the largest amount allowed for one transaction;
  • the daily exposure limit, the largest total amount allowed for successful transactions of that kind on the same date.

The limits are applied as follows:

  • A transaction fails if its amount exceeds the applicable maximum instruction limit.
  • A transaction fails if adding its amount to the customer's previously successful transactions of the same kind on that date would exceed the applicable daily exposure limit. A failed transaction does not add to the total, so a later smaller transaction may still succeed.

Write a program that enforces these limits and reports the result of each transaction instruction.

Input

Each input line is a banking record made of comma-separated fields. The first field determines the record type.

  • A 1 record is a customer record with six fields. The second field is the customer name, exactly eight uppercase letters. The remaining four fields are, in order, the customer's IAT maximum instruction limit, IAT daily exposure limit, payment maximum instruction limit, and payment daily exposure limit.
  • A 2 record is an account record with three fields. The third field is the account number, exactly six digits. This record states that the account is owned by the customer named in the second field.
  • A 5 record is an instruction record with six fields. The second through sixth fields are the transaction timestamp in YYYYMMDDhhmmss format, the customer making the transaction, the source account, the amount, and the destination account.
  • A 9 record ends the input and has one field.

All amounts are dollar-and-cent values written with a decimal point and exactly two cent digits, without comma separators. The maximum amount is $9,999,999.99. All 1 records appear before all 2 records, all 2 records appear before all 5 records, and the 9 record appears last.

Every customer name in a 2 or 5 record is valid and appears in exactly one 1 record. Every account number in a 5 record is valid and appears in exactly one 2 record. The 5 records are given in increasing timestamp order. There are at most 50 customers and 200 accounts.

The bank does not accept transactions from 23:00 through 06:00, so no input transaction has a timestamp in that range.

Output

For each 5 record, output one line. It must begin with INSTRUCTION n: , where n is the instruction number starting from 1, followed by exactly one of these messages:

  • NOT OWNER if the source account is not owned by the customer making the transaction;
  • IAT MAX EXCEEDED or PAYMENT MAX EXCEEDED if the amount exceeds the applicable maximum instruction limit;
  • IAT DEL EXCEEDED or PAYMENT DEL EXCEEDED if the amount would exceed the applicable daily exposure limit;
  • IAT OK or PAYMENT OK if the transaction succeeds.

If a transaction fails both limit checks, output only the corresponding MAX EXCEEDED message.