Business Magic
면접 대비시간 제한2초메모리 제한1024 MB
하나의 구간을 골라 값을 두 배로 만들고 그 구간 밖의 매장은 원하면 부호를 바꿔, 만들 수 있는 최대 총합을 구한다.
문제
There are stores located along a street, numbered from to from nearest to farthest. Last month, the store had a net profit of . If is positive, it represents a proft of dollars; if is negative, it represents a loss of dollars.
As a master of business magic, you have two types of spells at your disposal that you can use to alter the net profts of these stores for the next month:
- Blue Magic: You can choose a single continuous interval . The effect of this spell will be to double the net profit of every store from store to store (inclusive) for the next month. That is, if , then store will have net profit next month.
- Green Magic: You can choose any store and cast the green magic on it. The effect of the green magic is to change the next month’s net profit of that store to the negative of its last month’s net profit.
Any store that has not been affected by either spell will have the same net profit next month as it did last month.
However, there are some restrictions when casting spells. You can only cast the blue magic once and it must be used before the green magic. Additionally, the green magic cannot be cast on any store that has already been affected by the blue magic. Your task is to determine the maximum possible sum of the net profits for all stores for the next month after casting your spells optimally.
입력
The first line contains an integer , the number of stores. The second line contains space-separated integers , where is the net profit of store last month.
출력
Output a single integer, the maximum possible total net profit of all stores for the next month after casting the spells optimally.
제한
- for