#K65077. Transaction Validation
Transaction Validation
Transaction Validation
In this problem, you are given details of a series of transactions made on an account. Each transaction is represented by a pair of integers: a timestamp and an amount to be deducted from the account. The transactions must satisfy the following criteria to be considered valid:
- The transaction amount must not exceed a given limit (L). That is, every transaction (a_i) must satisfy (a_i \leq L).
- Transactions must be provided in non-decreasing order of timestamps. In other words, if transaction (i) occurs before transaction (j), then (t_i \leq t_j).
- The account balance should never become negative after any transaction. The balance after each transaction is computed as (B_{i} = B_{i-1} - a_i), with (B_0) being the initial balance.
If all transactions meet these conditions, the sequence is deemed valid and you should output "Valid transactions". Otherwise, output "Invalid transactions".
inputFormat
The input is provided via standard input (stdin) with the following format:
- The first line contains two space-separated integers: (L) (the transaction amount limit) and (B_0) (the initial account balance).
- The second line contains a single integer (n), the number of transactions.
- This is followed by (n) lines, each containing two space-separated integers: (t_i) (the timestamp of the transaction) and (a_i) (the amount of the transaction).
outputFormat
Output a single line to standard output (stdout) containing either "Valid transactions" if all the transactions satisfy the conditions, or "Invalid transactions" if any of the conditions are violated.## sample
100 50
3
0 25
10 20
20 5
Valid transactions