#C2856. Highest Possible Balance Calculator

    ID: 46218 Type: Default 1000ms 256MiB

Highest Possible Balance Calculator

Highest Possible Balance Calculator

This problem requires you to simulate a series of banking transactions and determine the highest balance attained throughout the process. You are given an initial balance of 0. Then, you will process a list of transactions. Each transaction is represented by a letter and an integer, where 'D' denotes a deposit (adding money) and 'W' denotes a withdrawal (subtracting money). Your task is to compute the highest balance observed after applying each transaction sequentially.

The simulation must be performed efficiently in a single pass over the transactions.

inputFormat

The input is read from standard input (stdin). The first line contains a single integer n (1 ≤ n ≤ 105), representing the number of transactions. Each of the following n lines contains a transaction in the format: X amount. Here, X is either 'D' for deposit or 'W' for withdrawal, and amount is a positive integer.

outputFormat

Print a single integer to standard output (stdout) representing the highest balance achieved after processing all transactions.## sample

6
D 100
W 50
D 200
W 150
D 300
W 100
400