#K47447. Final Score Calculation
Final Score Calculation
Final Score Calculation
You are given an initial score S and a sequence of operations. Each operation is a string formatted as increase X
or decrease X
, where X is an integer.
Your task is to compute the final score after processing all the operations in order. Specifically, if the operation is increase X
, add X to the current score; if it is decrease X
, subtract X from the current score.
The computation can be expressed mathematically as follows:
$$S_{final} = S + \sum_{i=1}^{N} \Delta_i$$
where $$\Delta_i = \begin{cases} +X_i, & \text{if the } i^\text{th} \text{ operation is } \texttt{increase } X_i \\ -X_i, & \text{if the } i^\text{th} \text{ operation is } \texttt{decrease } X_i \end{cases}$$
Implement a solution that reads input from stdin and prints the result to stdout.
inputFormat
The input is given in the following format:
- The first line contains an integer S, the initial score.
- The second line contains an integer N, the number of operations.
- The following N lines each contain an operation string in the format
increase X
ordecrease X
.
outputFormat
Output a single integer which is the final score after performing all the operations.
## sample100
3
increase 50
decrease 20
increase 30
160