International Collegiate Programming Contest
Time limit1sMemory limit128 MB
Given the exact output of a banking simulator, rebuild the canonical input: map each result line to a fixed request and choose the smallest initial balance B that keeps every request valid.
- Level
Hard8 of 10
- Topics
- Simulation, Implementation, Greedy, Math
- Solved
- No attempts yet
Problem
Do you have any idea how much work a contest like this takes? Reserving rooms, installing computers, buying food, printing certificates, and that is only part of the list. Since the first CTU contest in 1995 the organizers have spent a lot of sleepless nights, all so that people like you can enjoy the ICPC.
The problem set needs the most care of all. Writing the statements is not enough, because solutions and test data have to be prepared too. Please help us with the test data for the on-line banking problem. Here is what the banking program does.
The banking program reads several scenarios. A scenario starts with a line holding one positive integer , the number of accounts that exist when the supervision starts, . Each of the next lines holds an account number, one space, and the starting balance of that account. Every line after that is one request, and a scenario holds between and requests.
The last request of a scenario is followed by a line holding end and one empty line, and then the next scenario begins. A line holding 0 in place of closes the whole input.
An account number is exactly four decimal digits, then a slash, then one more digit that is the code of the bank keeping the account. Every bank has its own code. An amount is a non-negative decimal number with exactly two digits after the decimal point, at most 10000.00, written without unnecessary leading zeros, so only an amount below 1.00 starts with a zero. A starting balance uses the same notation and has no upper limit.
For every request the banking program prints one line: the command, then the amount parameter if the command has one, then a colon, one space, and the result.
create: if the same bank already keeps an account with that number, the result is already exists. Otherwise the account is opened with balance 0.00 and the result is ok.
For every command other than create, if any account number given as a parameter belongs to no account, the result is no such account. When the accounts do exist, the rules below decide the result.
deposit: the result is always ok, and the amount is added to the balance.
withdraw: if the balance is strictly lower than the amount, the result is insufficient funds. Otherwise the amount is subtracted and the result is ok.
transfer: if the two account numbers are equal, bank code included, the result is same account. Otherwise, if the balance of the source account is lower than the amount, the result is insufficient funds. Otherwise the money moves, and the result is ok when both accounts belong to the same bank or interbank when they belong to different banks.
After each scenario the banking program prints end and one empty line. After the end of the last scenario it prints one more line holding goodbye.
Your job is to build an input that makes the banking program print a given output. A huge number of inputs produce the same output, so the output section fixes one canonical shape and you print that one.
Input
The input is the complete output of one correct run of the banking program, so at least one input that produces it exists. Each scenario holds between and result lines.
Output
Print an input for the banking program that produces exactly the given output, built in the canonical shape below.
Turn every result line of a scenario into one request. In the table, is the amount printed on the result line, copied character for character, and is the number of create requests answered with ok so far in the current scenario, this one included.
Every scenario declares exactly four accounts, printed before its requests in this order.
is the smallest balance for which the requests above still produce the required results. Print it with exactly two digits after the decimal point and without unnecessary leading zeros.
After the requests of a scenario print end and one empty line. After the last scenario print a line holding 0.