##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
3 2 3 5
5 4 1 1 1 3
6 3 1 10 1 1 5
8
16
31
You are given an array of length .
In one operation, you choose a segment with , and then for every index such that you set .
You may apply the operation any number of times (possibly zero). Your goal is to maximize the sum .
Scenario 1: Array: . No interior positions exist (need , but only elements). No operations possible. Answer .
Scenario 2: Array: . Operation on : , raises all interior elements (indices ) from to . Final array: . Answer .
Scenario 3: Array: . Operation on : , raises indices from to . Operation on : , raises index from to . Final array: . Answer .