Plus or Times
InterviewTime limit1sMemory limit2048 MB
Given a starting value P and N rounds where each round offers either adding c or multiplying by c, find the maximum final value.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
Adrian is playing a game. When the game starts, Adrian is given points as his initial points. The game consists of rounds, numbered from 1 to . In round , Adrian has two options. Each option is one of the following two types.
+ c () adds to his current points.
x c () multiplies his current points by .
Adrian wants to maximize his points at the end of the game. Find the maximum points Adrian can have after completing all rounds.
Input
The first line contains two integers and (, ). Each of the next lines contains the two options of one round, separated by a space. Each option has the form T c, where is + or x. If is +, then . If is x, then .
Output
Print the maximum points Adrian can achieve as an integer on a single line.