#K89187. Taco Resource Management Simulation

    ID: 37475 Type: Default 1000ms 256MiB

Taco Resource Management Simulation

Taco Resource Management Simulation

You are given an initial amount of resources R and a sequence of actions that affect the resources. Each action is represented as a string. There are two types of actions:

  • mine X: Increase the number of resources by X.
  • build X: Decrease the resources by X if the current resource amount is at least X; otherwise, ignore the action.

Your task is to simulate the sequence of actions starting from the initial resources. The final output should be the amount of resources after processing all actions.

Note: Input is provided via stdin and output should be printed to stdout.

The process can be summarized by the following algorithm: $$ \text{resources} = R\\ \text{for each action in actions:}\\ \quad \text{if action is } \texttt{mine}\ X:\quad \text{resources} = \text{resources} + X\\ \quad \text{if action is } \texttt{build}\ X:\quad \text{if } \text{resources} \ge X \text{ then } \text{resources} = \text{resources} - X\\ $$

inputFormat

The input format is as follows:

R
N
action1
action2
... 
actionN

Where:

  • R is a positive integer representing the initial amount of resources.
  • N is an integer representing the number of actions.
  • Each of the following N lines contains an action in the format "mine X" or "build X", where X is a positive integer.

outputFormat

Output a single integer representing the final amount of resources after processing all the given actions.

## sample
100
5
mine 50
build 120
mine 30
build 200
mine 20
80

</p>