#K65507. Maximum Books Borrowed
Maximum Books Borrowed
Maximum Books Borrowed
You are given a series of events representing book borrowings and returns. Each event is described by three values: an event type (Borrow
or Return
), a timestamp, and the number of books involved. When a Borrow
event occurs, the count of borrowed books increases; when a Return
event occurs, it decreases.
Your task is to simulate the events (after sorting them in increasing order by timestamp) and determine the maximum number of books that were simultaneously borrowed at any point in time. Formally, if you maintain a counter \(current\_books\) that increases by \(b_i\) on a Borrow
event and decreases by \(r_i\) on a Return
event, report the maximum value of this counter throughout the simulation.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (n) which denotes the number of events. Each of the following (n) lines contains an event represented by three items separated by spaces: EventType
(either Borrow or Return), Timestamp
(an integer), and NumberOfBooks
(an integer).
outputFormat
Output a single integer to standard output (stdout) representing the maximum number of books borrowed at any given time after processing the events.## sample
5
Borrow 1 3
Borrow 2 2
Return 5 1
Borrow 6 4
Return 7 3
8
</p>