Messy Kevin XI
Kevin finally managed to get an internship! He's just started working at his new job and needs to organise his daily schedule. He has discovered that his productivity follows a very specific pattern throughout the day.
Kevin's energy level starts at at the beginning of the day. Every hour, his energy changes based on the activities he does:
- During work hours (activity type 'W'), his energy decreases by the amount of work intensity
- During break hours (activity type 'B'), his energy increases by the amount of rest he gets
- During coffee hours (activity type 'C'), his energy increases by twice the amount of caffeine intake (because Kevin loves caffeine!)
However, Kevin is very particular about his energy levels. If his energy ever drops below , he becomes grumpy and his productivity suffers for the rest of the day. Once Kevin becomes grumpy, his energy level stays at whatever negative value it reached, and no further activities can change it.
Given Kevin's schedule for the day, determine his final energy level. If Kevin never becomes grumpy, output his final energy level. If he becomes grumpy at any point, output the energy level when he first became grumpy.
Input
The first line contains an integer
, the number of activities Kevin has scheduled.
The next lines each contain a character and an integer
and
, where
is one of 'W', 'B', or 'C', representing the activity type, and
is the intensity/amount for that activity.
Output
Output a single integer: Kevin's energy level when he first becomes grumpy (negative), or his final energy level if he never becomes grumpy.
Example
Input 1
5
B 10
W 5
C 3
W 8
B 2
Output 1
5
Kevin's energy changes as follows:
- Start: 0
- After break (+10): 10
- After work (-5): 5
- After coffee (+6, since 2×3=6): 11
- After work (-8): 3
- After break (+2): 5
Kevin never becomes grumpy, so his final energy level is 5.
Input 2
4
W 5
B 3
W 10
C 4
Output 2
-5
Kevin's energy changes:
- Start: 0
- After work (-5): -5
Since Kevin's energy dropped below 0 after the first activity, he becomes grumpy and his energy stays at -5 for the rest of the day, regardless of subsequent activities.
Comments