UVa 10700

From Algorithmist
Jump to navigation Jump to search

10700 - Camel Trading[edit]

Summary[edit]

Given is an equation consisting of some positive integers, and + and * signs. Determine the maximal and the minimal value that can be obtained by adding parentheses into the expression.

Explanation[edit]

To find the maximum value, do the addition first, then the multiplication. Similiarly, to find the minimium value, do the multiplication first, then the addition.

Gotcha[edit]

Remember to use a 64-bit integer type as is bigger than . (Refer to the sample input.)

Implementations[edit]

Input[edit]

4
1+2*3*4+5
4*18+14+7*10
3+11+4*1*13*12*8+3*3+8
20*20*20*20*20*20*20*20*20*20*20*20 

Output[edit]

The maximum and minimum are 81 and 30.
The maximum and minimum are 1560 and 156.
The maximum and minimum are 339768 and 5023.
The maximum and minimum are 4096000000000000 and 4096000000000000.